开发者

Joining a table with itself via many-to-many in Rails

开发者 https://www.devze.com 2022-12-18 20:20 出处:网络
In my database, OptionSets are associated with other OptionSets.If I was joining two separate tables I would create a simple join table.However, Rail开发者_StackOverflows likes to have its foreign key

In my database, OptionSets are associated with other OptionSets. If I was joining two separate tables I would create a simple join table. However, Rail开发者_StackOverflows likes to have its foreign keys named <singular_table_name>_id, i.e. optionset_id. However, if I am joining the table with itself I obviously cannot give the two tables the same name. How do I deal with this?

create_table :optionsets_optionsets do |t|
  t.column :optionset_id, :integer
  t.column :dependent_optionset_id, :integer # how do i deal with this?
end


Dude there was a perfect answer to your question:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消