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