postgresql - Rails: what is the best way to model this has_and_belongs_to_many association -
postgresql - Rails: what is the best way to model this has_and_belongs_to_many association -
let's have 2 models event
, person
.
many people attend event , person can attend many events too.
class event < activerecord::base has_and_belongs_to_many :people end class person < activerecord::base has_and_belongs_to_many :events end create_table "events_people", :id => false, :force => true |t| t.integer "event_id" t.integer "person_id" end
the problem event presented 1 or many speakers
. particular event
, should have people
attend event , 1 or many speakers
are, of course, people too.
how do ? give thanks you.
try this:
class event < activerecord::base has_and_belongs_to_many :people has_and_belongs_to_many :speakers, :class_name => "person" end
and have events_speakers
bring together table match event_id
, person_id
(which point ids in people
table).
ruby-on-rails postgresql activerecord
Comments
Post a Comment