如何将类与数据库的特定表链接

时间:2019-02-12 14:19:50

标签: ruby-on-rails ruby

所以我正在尝试将一个类链接到数据库的特定表,到目前为止,我确实有我的类,并且我认为我也有该表,但是如何链接它们呢?

在我的程序中,我有一个类客户端,并且我希望每个客户端都具有指向具有配置表的链接。

这是迁移。

谢谢

class ClientsConfigSettings < ActiveRecord::Migration
  def change
    create_table "clients_config" do |t|
      t.boolean "when_credential_blocked", default: true
    end
  end
end

1 个答案:

答案 0 :(得分:0)

添加references

class ClientsConfigSettings < ActiveRecord::Migration
  def change
    create_table "clients_config" do |t|
      t.references :client
      t.boolean "when_credential_blocked", default: true
    end
  end
end

这会将client_id添加到新表中。因此,可以使用此列将这两个表连接起来。