On Tue, Jan 10, 2012 at 11:23 PM, Mohamad El-Husseini <
[email protected]> wrote:
> Another newbie question. My dummy app has the following models:
>
> class User < ActiveRecord::Base
> has_one :list
>
Try to add here:
has_one :list_with_celebs, :class_name => "List", :include => :celebs
end
>
> class List < ActiveRecord::Base
> belongs_to :user
> has_many :celebs
> end
>
> class Celeb < ActiveRecord::Base
> belongs_to :list
> end
>
> I want to load a user's list, and include the celebs that belong to it. I
> tried the following:
>
> @user = current_user
>
> ... @list = user.list.joins(:celebs)
> ... @list = user.list(:include => :celebs)
> ... @list = user.list.includes(:celebs)
>
@user.list_with_celebs
HTH,
Peter
--
Peter Vandenabeele
http://twitter.com/peter_v
http://rails.vandenabeele.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.