Suppose I have the following models:

  class Post < ActiveRecord::Base
    has_and_belongs_to_many :categories
    named_scope :active, :conditions => {:active => true}
  end

  class Category < ActiveRecord::Base
    has_and_belongs_to_many :posts
  end

I can call Post.active to get the set of all active Post objects. And
I can call some_category.posts.active to get all active Post objects
associated with some_category.

But what if I want slightly different semantics for the active posts
within a category? Perhaps there is an additional condition that
should apply in this case, as suggested by the new method shown here:

  class Category < ActiveRecord::Base
    has_and_belongs_to_many :posts

    def self.active_posts
      channels.active.all :conditions => {:show_in_category => true}
    end
  end

Instead of introducing a new active_posts method, is there any way to
define conditions that should be merged into the named_scope when it
is reference from the associated class?

-Sven
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to