Re: [MongoMapper] many to EmbeddedDocument

23 views
Skip to first unread message

Jamie Orchard-Hays

unread,
Apr 8, 2013, 11:07:02 AM4/8/13
to mongo...@googlegroups.com
They won't be the same EmbeddedDocument, so it doesn't quite make sense. Mongodb isn't a relational db, but you're putting a relational pattern on these collections. Perhaps rethink what you're trying to accomplish in the context of Mongodb as a document db?

Have a look at this: 

On Apr 5, 2013, at 9:11 PM, Eric Anderson wrote:

The setup:

class A
  include MongoMapper::Document
  # many :cs, dependent: destroy
end
class B
  include MongoMapper::Document
  many :cs
end
class C
  include MongoMapper:EmbeddedDocument
  belongs_to :b
  belongs_to :a
end

I basically want to un-comment the commented line. My embedded document is acting a join table. If I delete a B object then all the related C objects are removed since it is an embedded document. But if I delete an A object it doesn't delete all the related C objects. Is there a way to define a relationship in A to the related C objects and have cascading deletes. Or do I just need to implement a custom before_destroy callback on the A object?

Eric

--
--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "MongoMapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongomapper...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Eric Anderson

unread,
Apr 11, 2013, 7:36:34 PM4/11/13
to mongo...@googlegroups.com
On Monday, April 8, 2013 11:07:02 AM UTC-4, jamieorc wrote:
They won't be the same EmbeddedDocument, so it doesn't quite make sense. Mongodb isn't a relational db, but you're putting a relational pattern on these collections. Perhaps rethink what you're trying to accomplish in the context of Mongodb as a document db?

Thanks for the feedback. I know Mongo doesn't excel at relational data. But in my case the proper model is relational (they are independent entities that can have some relation). It seems to me that MongoMapper tries to make up for Mongo's lightweight relational support (via belongs_to, many, etc.). Was hoping for something to support my models out the box. But since MongoMapper doesn't have it, no big deal. Just wrote a custom method and callback on the model to provide what I need.
This is essentially what I have. But instead of using a array of ID's I have an array of models to establish the relationship (since there is relevant info in the relationship itself).

Eric 

Jamie Orchard-Hays

unread,
Apr 12, 2013, 10:18:34 AM4/12/13
to mongo...@googlegroups.com
You'll definitely want relations in MM, but it's important to rethink how you approach those relations in MM. The first thing I'd analyze is whether you actually need those join Models/Collections. You may decide you do, but worth thinking about.


Reply all
Reply to author
Forward
0 new messages