Generating a model with many to many in Ruby on Rails

前端 未结 3 1921
深忆病人
深忆病人 2021-02-07 12:31

Is there a way to generate a Rails model with a many to many relationship predefined? I know how to add it to the Active Record after the fact but it would be nice to have it de

3条回答
  •  没有蜡笔的小新
    2021-02-07 13:05

    You can use this reference from the Rails Guides.Here is the link. Also you will need to manually create the join table for those models using a migration.

    e.g

        create_table :assemblies_parts, :force => true do |t|
          t.integer :assembly_id
          t.integer :part_id
        end
    

提交回复
热议问题