# Using with\_scope with more than one model

**URL:** <https://www.ruby-forum.com/t/using-with-scope-with-more-than-one-model/109136>\
**Category:** Rails\
**Created:** [July 11, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/using-with-scope-with-more-than-one-model/109136 "2007-07-11T19:50:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chinmay\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/77aa72/32.png) [@Chinmay\_K](https://www.ruby-forum.com/u/Chinmay_K)\
**Post date:** [July 11, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/using-with-scope-with-more-than-one-model/109136/1 "2007-07-11T19:50:09Z")

</div>

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](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](http://Nabble.com).
