I’ve got a question about active-record association in Rails.
I’m developing three active-record model: Team, Teamuser, users, testing on “has_many through” association.
basically, I just want to be able to call team.users and user.teams.
here are my model definitions
team.rb
#######
class Team < ActiveRecord::Base
has_many :teamusers, :foreign_key => :team_id
has_many :users, :through => :teamusers
end
and
teamuser.rb
###########
class Teamuser < ActiveRecord::Base
belongs_to :teams
belongs_to :users
end
then
user.rb
########
class User < ActiveRecord::Base
has_many :teamusers, :foreign_key => :user_id
has_many :teams, :through => :teamusers
end
every time I try this
team.users
it returns me an error saying “uninitialized constant Team::Users”.
what might I be wrong he?
any advice would be very much appreciated.
Your Teamuser should be: