:through not working as I expected

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?

On Dec 4, 2007 2:02 AM, Ayyanar Aswathaman
[email protected] 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/

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs