Rails has_many through migration

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

im doing a many to many association with my models i belive after i did this:

class Competence < ActiveRecord::Base     has_many :behaviour, through: :behaviours_rel     has_many :stabilizer, through: :stabilizers_rel end  class Behaviour < ActiveRecord::Base     belongs_to :competence end  class Stabilizer < ActiveRecord::Base     belongs_to :competence end 

i have to do a migration something like

rails generate migration behaviour:belongs_to  

but it doesnt work i dont get the logic of doing this migration with rails generate

im trying to save in a competence serveral behaviours so a one to many rel is not enought

btw i dont want to explicitly do with sql the table so is there a way to do this migration in rails?

回答1:

$ rails g model behaviours_rel competence_id:integer behaviour_id:integer  $ rails g model stabilizers_rel competence_id:integer stabilizer_id:integer  $ bundle exec rake db:migrate 

See: http://www.codequizzes.com/learn-rails/many-to-many-relationships



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!