belongs_to vs belongs_to_related, has_many vs has_many_related

不羁岁月 提交于 2019-12-12 19:24:15

问题


What does the _related add to a relation? For example what is the difference between belongs_to and belongs_to_related? I'm mostly seeing this in Mongoid apps but not sure if it applies to Rails in general as well.


回答1:


belongs_to_related represents a relational association to a “parent” object.

please check this issue and the example given here on GitHub:

https://github.com/mongoid/mongoid/issues/348

See also:

http://rubydoc.info/gems/mongoid-with-auth/1.9.4/Mongoid/Associations/BelongsToRelated


has_many_related represents a relational one-to-many association with an object in a separate collection or database.

See also:

http://rubydoc.info/gems/mongoid-rails2/1.9.4/Mongoid/Associations/HasManyRelated

http://groups.google.com/group/mongoid/browse_thread/thread/29133cb1691e7db2/7d973df673861264



来源:https://stackoverflow.com/questions/7761602/belongs-to-vs-belongs-to-related-has-many-vs-has-many-related

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!