【问题标题】:Joining a table with itself via many-to-many in Rails在 Rails 中通过多对多连接一个表
【发布时间】:2010-01-31 09:24:33
【问题描述】:

在我的数据库中,OptionSet 与其他 OptionSet 相关联。如果我要连接两个单独的表,我会创建一个简单的连接表。然而,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

【问题讨论】:

    标签: ruby-on-rails models


    【解决方案1】:

    老兄,你的问题有一个完美的答案:

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

    【讨论】:

    • 老兄,我怎么没看到?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    相关资源
    最近更新 更多