使用ruby中的外键在轨道上添加字段
我有一个名为family
的表,该表的键称为susemy_id
,它是sumage> sumage
表的外键。是否有一种方法可以返回带有来自family
表的数据的调查
模型。
I have a table called family
that has a key called survey_id
that is a foreign key to the survey
table. Is there a way to return a survey
model with data from the family
table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在家庭模型中指定关联
属于:调查
。然后,您可以检索关联的模型instance_of_family_model.survey
建议阅读此 https://guides.rubyonrails.orgs.org/association_basics.html
Specify association in Family model
belongs_to :survey
. Then you can retrieve associated modelinstance_of_family_model.survey
Recommend reading this https://guides.rubyonrails.org/association_basics.html
您可以在
family
模型上指定调查
关联,并且可以在
family> family 模型的任何实例上获得
survey>
You can specify
survey
association onFamily
modelAnd than you can get
survey
on any instance ofFamily
model