From: Christian Kerth Date: 2007-11-16T22:05:37+09:00 Subject: Re: ActiveRecord Problem Todd Benson wrote: > On Nov 16, 2007 4:23 AM, Christian Kerth > wrote: >> ich m�chte die n:m beziehung zwischen users und courses �ber > useres_course modellieren. >> has_many :users, :through => :users_courses >> >> u = User.find(:first, :conditions => [ "username = ?", session["user"]]) >> usercourses = u.users_courses.collect{|x| x.courses} >> >> bekomm ich den Fehler: uninitialized constant User::UsersCourse >> >> hat jemand eine Idee? > > I don't know any German, but I can guess that your problem is with > your UserCourse class model. It doesn't seem like it matches your > table name. The #set_table_name and #set_primary_key methods help, if > you want to match a database. I've played around with this quite a > bit. > > I don't know your exact model either, but maybe... > > class UserCourse < ActiveRecord::Base > set_table_name :users_courses > belongs_to :course > belongs_to :user > end > > hth a lit, > Todd I tried to modify my models: class UserCourse < ActiveRecord::Base set_table_name 'users_courses' set_primary_key 'users_Id' set_primary_key 'courses_Id' belongs_to :course belongs_to :user end class User < ActiveRecord::Base set_table_name 'users' set_primary_key 'Id' has_many :users_courses has_many :courses, :through => :users_courses end class Course < ActiveRecord::Base set_table_name 'courses' set_primary_key 'Id' has_many :users_courses has_many :users, :through => :users_courses end The task is to select e.g. all attributes from UserCourse for a certain User and Course. I keep getting the same error. How do a create a many to many realtion with attributes at all in activerecord? thx ck -- Posted via http://www.ruby-forum.com/.