has_many :through behaviour trouble

Hi there!

I have the following classes, but I don't undersant why, when I try to
create some

class Wishlist < ActiveRecord::Base
  has_many :activated_user_wishlists, :class_name => "UserWishlist",
:conditions => {:registered => true}
  has_many :users_registered, :through => :activated_user_wishlists,
:class_name => "User", :source => "wishlist"
end

class UserWishlist < ActiveRecord::Base
  belongs_to :wishlist
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :user_wishlists
  has_many :wishlists, :through => :user_wishlists
end

And when I try to do that:
Wishlist.first.users_registered << User.first
And then look at the join table, that's what I see:

#<UserWishlist user_id: nil, wishlist_id: 1, admin: false, registered:

]

Someone know why user_id is nil?

Hi Guillem Vidal,

There was a small issue with association build on Wishlist Model.

class Wishlist < ActiveRecord::Base
has_many :activated_user_wishlists, :class_name => "UserWishlist",
:conditions => {:registered => true}
has_many :users_registered, :through => :activated_user_wishlists,
:source => :user
end

You can use the above mentioned code(changes in users_registered
association). Then it will works fine.

In has_many :through association, specifying the source(Model name) is
enough.

Cheers,
vadivelan