On Nov 24, 5:43 pm, Sven <[EMAIL PROTECTED]> wrote:
> Given these models
>
> class Category < ActiveRecord
> has_many :category_assignments
> has_many :posts, :through => :category_assignments
> end
>
> class CategoryAssignment < ActiveRecord::Base
> belongs_to :post
> belongs_to :category
> # Has boolean column 'featured'
> end
>
> class Post < ActiveRecord::Base
> has_many :category_assignments
> has_many :categories, :through => :category_assignments
> end
>
> I want to add a named_scope to Post that will return all featured
> posts. But the semantics of this named_scope vary depending upon
> whether I am calling the named scope on Post or on category.posts:
> Post.featured
> is simple enough. The definition
> named_scope :featured,
> :joins => :category_assignments,
> :conditions => {:category_assignments.featured => true }
> will return all posts for which any associated category_assignment
> record has featured = true.
>
> But when I take a category instance and call category.posts.featured I
> want to get all of the posts which are featured *in that category*,
> which requires restricting by category_id. To do this properly the
It should do that by itself. You shouldn't need to do anything. Have
you tried it?
Fred
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---