I really didn’t know how to phrase the question better but here goes:
Lets say i have 2 models
class Record < ActiveRecord::Base
has_many :roles, :dependent => :destroy
end
class Role < ActiveRecord::Base
belongs_to :record
end
I want a way to make sure that every time a new record instance is created 2 new roles are created automatically by the system for that record.
each role will have a name, record_id, Boolean called edit and Boolean called review.
so if i create a record called Hello and it has an ID 1 then the system should create these 2 new roles at the same time:
Role 1: name: Hello edit, record_id: 1, edit: true, review: false
Role 2: name: Hello review, record_id: 1, edit: false, review: true
ActiveRecord callbacks to the rescue: