I’ve seen a lot of usage of with_scope since my last post, and
everywhere I
see code like this:
Mail.with_scope(:find=>{:conditions=>“user_id = …”}) do
count = Mail.count
end
Here, both the model used for scoping, and the model inside the scope is
the
same.
I’m trying to do something like this:
class User<ActiveRecord::Base
def among_friends
User.with_scope(:find => {:conditions => friends_scope_condition})
{yield}
end
end
so that I can do stuff like:
#Find friends’ quotes
current_user.among_friends do
@quotes_by_friends = Quote.find(:all, :order=>‘created_at DESC’)
end
Unfortunately, this doesn’t work, and to correct the code, I need to use
Quote.with_scope in the among_friends definition instead.
This defeats the purpose; which was to increase flexibility.
Would appreciate any ideas.
View this message in context:
http://www.nabble.com/Using-with_scope-with-more-than-one-model-tf4063505.html#a11545268
Sent from the RubyOnRails Users mailing list archive at Nabble.com.