Skip to content

Instantly share code, notes, and snippets.

@paul
Created August 27, 2008 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul/7527 to your computer and use it in GitHub Desktop.
Save paul/7527 to your computer and use it in GitHub Desktop.
<people>
<person>
<name>Paul</name>
<addresses>
<address>
<city>Boulder</city>
<state>Colorado</state>
</address>
</addresses>
</person>
</people>
class Person
include DataMapper::Resource
property :name, String
has n, :addresses
end
class Address
include DataMapper::Resource
property :city, String
property :state, String
belongs_to :person
end
def read_many(query)
pp query
Collection.new(query) do |collection|
@xml.find("/people/person").each do |item|
person = collection.load(
query.fields.map do |prop|
text_for_elem(item, prop_to_elem(prop))
end
)
a_query = Query.new(query.repository, Address)
a_collection = Collection.new(a_query) do |a_collection|
item.find("addresses/address").each do |a_xml|
a_collection.load(
a_query.fields.map do |prop|
text_for_elem(a_xml, prop_to_elem(prop))
end
)
end
end
person.send(:addresses_association).instance_variable_set(:@children, a_collection)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment