【发布时间】:2020-06-27 03:53:32
【问题描述】:
我正在尝试在另一个表中创建一个具有 2 个 FK 引用 1 个 PK 的表。
class CreateJobapps < ActiveRecord::Migration[5.1]
def change
create_table :jobapps do |t|
t.references :job, foreign_key: { job: :id }, index: { unique: true}
t.references :user, foreign_key: { user: :id }, index: { unique: true}
t.timestamps
end
end
end
这个方法正确吗?如果是这样,如果我提供受人尊敬的表的 FK,我如何获得输出。
这是我的 Jobapp 表的样子
我尝试使用Jobapp.joins(:user),但无济于事
我应该在模型文件中写belongs_to 或has_many 吗?
【问题讨论】:
标签: ruby-on-rails database postgresql rubygems relational-database