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"
end
class GroupUser < ActiveRecord::Base
belongs_to :group
belongs_to :user
end
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
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/reflection.rb\
: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:in `initialize''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/\
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:in `new''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations.\
rb:1306:in `users''
from (irb):2
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.