使用ruby中的外键在轨道上添加字段

发布于 2025-02-03 09:49:01 字数 166 浏览 1 评论 0原文

我有一个名为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木森分化 2025-02-10 09:49:01

在家庭模型中指定关联
属于:调查。然后,您可以检索关联的模型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 model instance_of_family_model.survey
Recommend reading this https://guides.rubyonrails.org/association_basics.html

卖梦商人 2025-02-10 09:49:01

您可以在family模型上指定调查关联

class Family < ApplicationRecord
  belongs_to :survey
end

,并且可以在 family> family 模型的任何实例上获得survey>

@family = Family.find(1)
@family.survey

You can specify survey association on Family model

class Family < ApplicationRecord
  belongs_to :survey
end

And than you can get survey on any instance of Family model

@family = Family.find(1)
@family.survey
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文