Has_many :through question

I am trying to create an association table using the “:through” option
in “has_many” but not having success. I have created the necessary
migrations of the association tables and run rake db:migrate

I have the following model:

class Group < ActiveRecord::Base
has_many :users, :through => :group_user
has_many :invites, :through => :group_invite, :class_name => “User”
belongs_to :owner, :class_name => “User”

class GroupUser < ActiveRecord::Base
belongs_to :group
belongs_to :user

Loading development environment (Rails 2.3.8)

g = Group.find(1)
=> #<Group id: 1, name: “My Group”, owner_id: 1, created_at: “2010-08-19
02:30:10”, updated_at: "
2010-08-19 02:30:10">

g.users << User.find(2)
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the
association :group_user
in model Group
:348:in check_validity!' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/\ association_proxy.rb:56:ininitialize’
association_collection.rb:20:in initialize' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations.\ rb:1306:innew’
rb:1306:in `users’
from (irb):2

Disregard, solution found.

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