开发者

Using Mongoid tree for many to many relationships in rails?

I just wanted to seek some advice on database desig开发者_如何学Pythonn with mongoid and rails.

If I have complex objects that need the ability to reference each other, would this be an appropriate solution.

class Tree
  include Mongoid::Document
  include Mongoid::Tree
end

class Group < Tree
end

class People < Tree
end

class Cars < Tree
end

etc...

So they can all belong to each other, be siblings or be children. Would this improve performance as they would all be in the same collection? Compared to if I was to use a habtm relationship between say 2, 3 or 4 models. Not entirely sure if separate models called in the same collection is faster or an appropriate design.

The main reason I tried this design was because I was reading the the idea behind nosql is to use nest objects to minimize calls to the database. Does it make any difference referencing a child object in the same collection compared to a separate collection? Or even across multiple collections?

There's a few questions here but hopefully someone could help point me in the right direction :)


yes, good choice! You want to use Inheritance like this to store them in the same collection. You'll only have to access one collection - which should make it faster accessing children / parents.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜