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
我必须进行类似
的迁移rails generate migration behaviour:belongs_to
但它不起作用我没有得到使用rails generate执行此迁移的逻辑
我试图在一定程度上保存一些行为,这样就不会有一对多的表现
顺便说一句,我不想明确地使用sql表,那么有没有办法在rails中进行这种迁移?
答案 0 :(得分: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
请参阅:http://www.codequizzes.com/learn-rails/many-to-many-relationships