# Complex relations

**URL:** <https://www.ruby-forum.com/t/complex-relations/171750>\
**Category:** Rails\
**Created:** [July 8, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/complex-relations/171750 "2009-07-08T16:25:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marek\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@marek\_j](https://www.ruby-forum.com/u/marek_j)\
**Post date:** [July 8, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/complex-relations/171750/1 "2009-07-08T16:25:12Z")

</div>

Hi,

I wanted to ask, whether someone could help me. I have in my project  
quite a lot of complex relations between my models. For example:

has\_many :some\_groups, :class\_name =\> ‘Group’, :finder\_sql =\> ’  
SELECT DISTINCT groups.\* FROM groups  
JOIN memberships ON memberships.group\_id=groups.id AND  
memberships.active = 1  
JOIN users ON memberships.user\_id = users.id AND users.active =  
1  
JOIN memberships AS ms ON ms.user\_id = users.id AND ms.active =  
1  
AND ms.group\_id = #{self.group.id}  
WHERE groups.kind\_id = 3

Is it possible to simplify such a thing into more rubyish code ?

Thanks

Marek
