mercredi 1 avril 2015

Rails: Relate two records after creation

I have his model in Rails:



class Commission < ActiveRecord::Base
has_and_belongs_to_many :books
end

class Book < ActiveRecord::Base
has_and_belongs_to_many :commissions
end


This model generates three tables: commission, book and books_commissions. In the first process of my app generate and save commissions and books without relating entries.


Question: How create a record in books_commissions if I know the book_id and commission_id?


Aucun commentaire:

Enregistrer un commentaire