Topic: How to model a bidirectional relationship between persons

I have a person table and I want these persons to be able to define 'friendhips' between each other.
A friendship is a bidirectional relationship between two (different) records in the persons table.

Another 'nice-to-have' would be an efficient way of finding all possible paths between two persons (either directly or transitive).

What's the common approach to this ? Maintaining the relationship in an association table (that points to both persons) isn't bidirectional and IMHO inefficient to search (transitively) due to the combinatorial explosion.

Re: How to model a bidirectional relationship between persons

See this related post on how to do a simple bidirectional relationship.

As for transitive searching, I can't think of an efficient way to do this off the top of my head. This reminds me of the tree problem which can be solved with something similar to acts_as_nested_set, but in this case you don't have one static root and it's a many-to-many association.

Perhaps this can be solved through caching, but that can get out of control too.

Railscasts - Free Ruby on Rails Screencasts