# Question about has\_many :through association

**URL:** <https://www.ruby-forum.com/t/question-about-has-many-through-association/179536>\
**Category:** Rails\
**Created:** [November 27, 2009, 2:52pm UTC](https://www.ruby-forum.com/t/question-about-has-many-through-association/179536 "2009-11-27T14:52:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![polarapfel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/958977/32.png) [@polarapfel](https://www.ruby-forum.com/u/polarapfel)\
**Post date:** [November 27, 2009, 2:52pm UTC](https://www.ruby-forum.com/t/question-about-has-many-through-association/179536/1 "2009-11-27T14:52:46Z")

</div>

Hi,

I have two models called Group and User. A group shall have a leader and  
several members, whereas leader and members are of type User.

I am using the following associations:

class Group \< ActiveRecord::Base  
has\_one :group\_leader, :class\_name =\> ‘User’  
has\_many :group\_members, :through =\> :group\_leader  
end

class User \< ActiveRecord::Base  
belongs\_to :group  
has\_many :group\_members, :class\_name =\> “User”, :foreign\_key =\>  
“group\_leader\_id”  
belongs\_to :group\_leader, :class\_name =\> “User”  
end

And also put the following into a migration  
add\_column :users, :group\_id, :integer  
add\_column :users, :group\_leader\_id, :integer

Then I assign a group leader to a group and a member to a leader. When I  
do a

Group.find(:first).group\_members I get the following exception:

ActiveRecord::StatementInvalid: Mysql::Error: Not unique table/alias:  
‘users’: SELECT `users`.\* FROM `users` INNER JOIN users ON  
users.group\_leader\_id = users.id WHERE ((`users`.group\_id = 8))

What is that all about? Any help is highly appreciated. Thank you!

Cheers,  
Tobi
