Association: has_many_reflexive?

So, I’m trying to make the sort of thing where you’d have an
intermediate join table which for simplicities sake, stores all the
friends for a person…

persons_table

id

friends_table

person_id_left
person_id_right

But, what’d be nice would be if it were unimportant from which side the
connection were made (i.e. non-directional graph), such that…
class Person
has_many :friends, :association_id =>
[“person_id_left”,"person_id_right]
end

person.friends => #SQL(“select * from persons_table join friends_table
on friends_table.person_id_left = #{self.id} or
friends_table.person_id_right = #{self.id}”)

Seems like a pretty common scenario, but my google searches aren’t
really turning up much, anybody done this?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs