# :through not working as I expected

**URL:** <https://www.ruby-forum.com/t/through-not-working-as-i-expected/122061>\
**Category:** Rails\
**Created:** [December 4, 2007, 9:02am UTC](https://www.ruby-forum.com/t/through-not-working-as-i-expected/122061 "2007-12-04T09:02:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayyanar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@ayyanar](https://www.ruby-forum.com/u/ayyanar)\
**Post date:** [December 4, 2007, 9:02am UTC](https://www.ruby-forum.com/t/through-not-working-as-i-expected/122061/1 "2007-12-04T09:02:33Z")

</div>

class Task \< ActiveRecord::Base  
belongs\_to :court  
has\_many :workflow\_tasks  
has\_many :task\_users, :dependent =\> :destroy  
has\_many :court\_users, :through =\> :task\_users  
has\_many :users, :through =\> :court\_users  
end

class CourtUser \< ActiveRecord::Base  
belongs\_to :court  
belongs\_to :user  
end

I accessed the users as follows:

task.users.collect{|user|user.name}.join(’,’) unless task.users.blank?

Following error thrown:

Mysql::Error: #42S22Unknown column ‘court\_users.task\_id’ in ‘where  
clause’: SELECT users.\* FROM users INNER JOIN court\_users ON users.id =  
court\_users.user\_id WHERE ((court\_users.task\_id = 3))

Anyone knows the issue?

---

<div class="post-metadata">

**Author:** ![ayyanar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@ayyanar](https://www.ruby-forum.com/u/ayyanar)\
**Post date:** [December 4, 2007, 10:25pm UTC](https://www.ruby-forum.com/t/through-not-working-as-i-expected/122061/2 "2007-12-04T22:25:45Z")

</div>

On Dec 4, 2007 2:02 AM, Ayyanar Aswathaman  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> belongs\_to :court  
> clause’: SELECT users.\* FROM users INNER JOIN court\_users ON users.id =  
> court\_users.user\_id WHERE ((court\_users.task\_id = 3))
> 
> Anyone knows the issue?

I’m guessing your court\_users table doesn’t have a task\_id column.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![ayyanar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@ayyanar](https://www.ruby-forum.com/u/ayyanar)\
**Post date:** [December 5, 2007, 5:59am UTC](https://www.ruby-forum.com/t/through-not-working-as-i-expected/122061/3 "2007-12-05T05:59:03Z")

</div>

Ayyanar Aswathaman wrote:

> class Task \< ActiveRecord::Base  
> belongs\_to :court  
> has\_many :workflow\_tasks  
> has\_many :task\_users, :dependent =\> :destroy  
> has\_many :court\_users, :through =\> :task\_users  
> has\_many :users, :through =\> :court\_users  
> end  
> …  
> Anyone knows the issue?

You can’t go through a through. You can only go through a regular  
has\_many.

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)
