当属vs.科目_相关,has_many与has_many_related [英] belongs_to vs belongs_to_related, has_many vs has_many_related

查看:102
本文介绍了当属vs.科目_相关,has_many与has_many_related的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

_related给关系添加了什么?例如,belongs_to和belongs_to_related之间有什么区别?我在Mongoid应用程序中经常看到这种情况,但不确定它是否也适用于Rails.

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.

推荐答案

belongs_to_related 表示与父"对象的关系关联.

belongs_to_related represents a relational association to a "parent" object.

请检查此问题以及GitHub此处给出的示例:

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

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

另请参阅:

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

has_many_related 表示与单独集合或数据库中的对象的一对多关系.

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

另请参阅:

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

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

这篇关于当属vs.科目_相关,has_many与has_many_related的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆