# Rails ORM Help

**URL:** <https://www.ruby-forum.com/t/rails-orm-help/168195>\
**Category:** Rails\
**Created:** [May 18, 2009, 6:31am UTC](https://www.ruby-forum.com/t/rails-orm-help/168195 "2009-05-18T06:31:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adeel\_bm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/47e85d/32.png) [@adeel\_bm](https://www.ruby-forum.com/u/adeel_bm)\
**Post date:** [May 18, 2009, 6:31am UTC](https://www.ruby-forum.com/t/rails-orm-help/168195/1 "2009-05-18T06:31:52Z")

</div>

In my scenario, I have two tables namely; contacts and contacts\_users.  
Table contacts consists of a primary key namely id and contacts\_users  
has fields; id, contact\_id, peer\_id and status.

contacts\_users is basically the recursive relation of a contact to its  
peers, which he/she invited and vice versa. In other words, in one case,  
the id of a person lies in the contact\_id field of contacts\_users and in  
other case the id of same person lies in peer\_id field. Moreover,  
peer\_id and contact\_id of contacts\_users constitute a composite key. So,  
in contacts\_users model i defined the said scenario like;  
validate\_uniqueness\_of :contact\_id, :scope=\>peer\_id  
Which means; if A adds B, then A is a contact of B and B is a contact of  
A as well, and the relation cannot be replicated.

Now what could be the relation of contacts\_users and contacts tables, so  
that I could do contacts.contacts\_users and get all the contacts of  
person A rather doing ContactsUsers.find\_by\_contact\_id\_or\_peer\_id?

Please Help.

---

<div class="post-metadata">

**Author:** ![adeel\_bm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/47e85d/32.png) [@adeel\_bm](https://www.ruby-forum.com/u/adeel_bm)\
**Post date:** [May 18, 2009, 7:15am UTC](https://www.ruby-forum.com/t/rails-orm-help/168195/2 "2009-05-18T07:15:00Z")

</div>

You could look for a Gem that handles Friendship. There are a few.

You could use and ORM called datamapper

On Mon, May 18, 2009 at 4:31 PM, Abm Abm
