activerecord organization question: removing has_many :through work
i'm building an app flush rails, i'm including 3 models (and emigration scripts) arrangement i'm perplexing do, isn't working. here's rundown: i have users concentration go teams, any organisation have churned coaches. i wish means lift list coaches convenient user.
for instance, user go teams t1 t2. teams t1 t2 have 4 opposite coaches each, manager common. i'd means lift list coaches simply saying:
u = user.find(1)
coaches = u.coaches
here emigration scripts, associations models. am i doing something wrongly design? associations correct?
class createusers < activerecord::migration
def self.up
create_table :users |t|
t.column :login, :string, :default => nil
t.column :firstname, :string, :default => nil
t.column :lastname, :string, :default => nil
t.column :password, :string, :default => nil
t.column :security_token, :string, :default => nil
t.column :token_expires, :datetime, :default => nil
t.column :legacy_password, :string, :default => nil
end
end
def self.down
drop_table :users
end
end
class createteams < activerecord::migration
def self.up
create_table :teams |t|
t.column :name, :string
end
end
def self.down
drop_table :teams
end
end
class teamsusers < activerecord::migration
def self.up
create_table :teams_users, :id => fake |t|
t.column :team_id, :integer
t.column :user_id, :integer
t.column :joined_date, :datetime
end
end
def self.down
drop_table :teams_users
end
end
here models (not whole file):
class user < activerecord::base
has_and_belongs_to_many :teams
has_many :coaches, :through => :teams
class organisation < activerecord::base
has_many :coaches
has_and_belongs_to_many :users
class manager < activerecord::base
belongs_to :teams
end
this happens i try lift coaches:
u = user.find(1)
=> #<user id: 1, firstname: "dan", lastname: "wolchonok">
>> u.coaches
activerecord::statementinvalid: mysql::error: #42s22unknown buttress 'teams.user_id' 'where clause': name `coaches`.* `coaches` middle join teams coaches.team_id = teams.id where ((`teams`.user_id = 1))
here's blunder sql:
mysql::error: #42s22unknown buttress 'teams.user_id' 'where clause': name coaches.* coaches middle join teams coaches.team_id = teams.id where ((teams.user_id = 1))
am i blank something :through clause? settlement totally off? someone indicate me right direction?
Comments
Post a Comment