Given two model classes, Foo
and Bar
, I want Foo to have 3 references to separate instances of Bar using 3 different property names, with the foreign key on the Foo table. Bar will be managed separately and can belong to many instances of Foo. This somewhat explains it, obviously has_one is the wrong association to use (I think?):
Foo
has_one :prop_a, :class_name => "Bar"
has_one :prop_b, :class_name => "Bar"
has_one :prop_c, :class_name => "Bar"
Bar
There are 3 potential types of Bar, denoted by a bar_type
string field, each reference on Foo corresponds to one of these. e.g. Foo.prop_a
references an instance of Bar with bar_type
= 'type_a'. How do I create this type of association in Rails?