Embedded / MongoDB docs with rails

I recently started playing with MongoDB on Rails using the MongoMapper gem. I was wondering if there is a way for the class / object / collection to be both Document and inline document. I want the same entity to be included / included in other documents and also be able to exist on its own as an object.

Is it possible? Am I viewing this problem incorrectly? Any discussion / advice would be much appreciated as internet resources seem low for this stuff right now.

+2


a source to share


1 answer


I have a very similar use and the requirement was to have (using your entity names):

  • collection with people
  • built-in BusinessPerson model that belongs_to_related :person

  • collection with businesses that embeds_many :busiess_people

The idea behind this was that I have additional fields in the BusinessPerson that might not apply if Person is also running another business. Let's say the role in this business, the email address or its share.



No, you could say that getting a business might look human, but it isn't:

class Person
   def businesses
     Business.where('business_people._id' => self.id)
   end
end

      

0


a source







All Articles