jack.tang
4/6/2007 8:01:00 AM
On Apr 6, 10:52 am, "jack.tang" <him...@gmail.com> wrote:
> Hi
>
> In the classic hasmanythrough example:
>
> class Group < ActiveRecord::Base
> has_many :memberships
> has_many :users, :through => :memberships
> end
>
> class User < ActiveRecord::Base
> has_many :memberships
> has_many :groups, :through => :memberships
> end
>
> group1 = Group.new(.....)
> group1.users = [User.find_by_id(2)]
> group1.save!
>
> it throws the exception: "users=" is one undefined method. So how can
> i save the relationship in hasmanythrough?
Hi Guys.
here is another question -- how can I load asscocitated class while
fetching. say
User.find_by_name("test").groups
The error is "NameError: uninitialized constant User::Groups" , my
rails version is 1.2.3.
Can you tell me how to enable :through function?
/Jack