Try to change : ------------------------------------------ class Role < ActiveRecord::Base belongs_to :packages belongs_to :users end --------------------------------------------
with : class Role < ActiveRecord::Base belongs_to :package belongs_to :user end it's the one of the rails conventions, 'belongs_to' should take as parameter the singular name of the model :) I hope it'will if not post me the log errors. 2011/9/4 Dave G. <[email protected]> > I'm trying to do, what seems like, a very basic join. However, the > association just doesn't seem to work. I'm sure it's something very > simple but I don't know what. > > class Role < ActiveRecord::Base > belongs_to :packages > belongs_to :users > end > > class Package < ActiveRecord::Base > has_many :roles > has_many :users, :through => :roles > end > > class User < ActiveRecord::Base > has_many :roles > has_many :packages, :through => :roles > end > > create_table "packages", :force => true do |t| > t.string "tracking" > t.datetime "created_at" > t.datetime "updated_at" > end > > create_table "roles", :force => true do |t| > t.integer "user_id" > t.integer "package_id" > t.string "role" > end > > create_table "users", :force => true do |t| > t.string "user_name" > t.string "first" > t.string "last" > end > > With that, I can do: > > @package = Package.new > @roles = @package.roles > > @roles.inspect # OK > > But I can't do: > > @package = Package.new > @users = @package.users > > or not: > > @package.roles.collect { |a| a.users } > @users = @package.users > > Nada... > > -- > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

