http://railstips.org/2009/6/27/mongomapper-the-rad-mongo-wrapper

Looks really sweet :) Here is an extract:

Looks pretty similar to the Hobo fields syntax in the model, except no
migrations are needed. Simplicity rules!!!
...

Embedded Documents

So the cool thing about Mongo is that you can embed documents in other
documents. Let’s say our person has multiple addresses. To handle
that, we would create an embedded address document to go along with
our person document.

class Address
  include MongoMapper::EmbeddedDocument

  key :address, String
  key :city,    String
  key :state,   String
  key :zip,     Integer
end

class Person
  include MongoMapper::Document

  many :addresses
end

Now we can add addresses to the person like so:

person = Person.new
person.addresses << Address.new(:city => 'South Bend', :state => 'IN')
person.addresses << Address.new(:city => 'Chicago', :state => 'IL')
person.save

Doing this actually saves the address right inside the person
document. Yep, no joins. Yay! Cheers resound from the heavens! You can
even query for documents based on these embedded documents. For
example, if you wanted to find all people that are in the city
Chicago, you could do this:

Person.all(:conditions => {'addresses.city' => 'Chicago'})

--

You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.


Reply via email to