代码之家  ›  专栏  ›  技术社区  ›  titaniumdecoy Mr. T

通过Rails中的多对多连接表本身

  •  1
  • titaniumdecoy Mr. T  · 技术社区  · 16 年前

    在我的数据库中,选项集与其他选项集相关联。如果我连接两个单独的表,我将创建一个简单的连接表。但是,Rails喜欢将其外键命名为<单数表格名称>_id,即optionset_id。但是,如果我将表本身连接起来,显然不能给这两个表赋予相同的名称。我该怎么处理?

    create_table :optionsets_optionsets do |t|
      t.column :optionset_id, :integer
      t.column :dependent_optionset_id, :integer # how do i deal with this?
    end
    1 回复  |  直到 16 年前
        1
  •  5
  •   Community Mohan Dere    9 年前

    哥们,你的问题有一个完美的答案:

    Many-to-many relationship with the same model in rails?