Hola,
Just wondering if rails will allow me to have one model belong to
another model via 2 foreign keys in the same table, not just one?
So like this…
Class Pair
belongs_to :individuals, :foreign_key => “individual_a”
belongs_to :individuals, :foreign_key => “individual_b”
end
Class Individual
has_many :pairs
end
my database table “pairs” has the following columns:
id
individual_a
individual_b
I want to be able to call ALL pairs that belong to an individual, who
could be listed as either “individual_a” or “individual_b”
So like
If my pair table had the following rows…
id | individual_a | individual_b
1 | bob | frank
2 | frank | dave
So we see that frank has 2 pairs, but is listed as individual_a in one,
and individual_b in the other.
I want to do something like
Individual.find(franks_id).pairs.all = [PairObject_1, PairObject_2]
… so that it returns every pair that frank is a part of, regardless of
if he is individual_a or individual_b
I hope that makes sense.
Cheers!