# \[PATCH\] (+tests) with\_scope :order doesn't work with include

**URL:** <https://www.ruby-forum.com/t/patch-tests-with-scope-order-doesnt-work-with-include/99506>\
**Category:** Rails\
**Created:** [July 23, 2006, 4:39pm UTC](https://www.ruby-forum.com/t/patch-tests-with-scope-order-doesnt-work-with-include/99506 "2006-07-23T16:39:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Kidd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c77e96/32.png) [@Eric\_Kidd](https://www.ruby-forum.com/u/Eric_Kidd)\
**Post date:** [July 23, 2006, 4:39pm UTC](https://www.ruby-forum.com/t/patch-tests-with-scope-order-doesnt-work-with-include/99506/1 "2006-07-23T16:39:56Z")

</div>

(I’ve had this patch lying around for a couple of weeks, waiting for  
Trac to come back up. noradio’s already had a look at it on IRC.  
What’s the best way to submit patches while Trac is down?)

with\_scope doesn’t support :order in the presence of :include. For  
example:

{{{

# We’re testing the interaction between :order, :include, and

with\_scope.  
TEST\_ORDER = ‘tickets.created\_at DESC’  
TEST\_INCLUDE = [‘owner’]  
def test\_find(opts1, opts2)  
Ticket.with\_scope(:find =\> opts1) do  
Ticket.find(:all, opts2).map {|t| t.id }  
end  
end

# In these examples, :order is respected.

test\_find({ :order =\> TEST\_ORDER }, {})  
test\_find({}, { :include =\> TEST\_INCLUDE, :order =\> TEST\_ORDER })  
test\_find({ :include =\> TEST\_INCLUDE }, { :order =\> TEST\_ORDER })

# In these examples, :order is ignored.

test\_find({ :include =\> TEST\_INCLUDE, :order =\> TEST\_ORDER }, {})  
test\_find({ :order =\> TEST\_ORDER }, { :include =\> TEST\_INCLUDE })  
}}}

There’s some code duplication between  
construct\_finder\_sql\_with\_included\_associations and the usual  
construct\_finder\_sql, and changeset r4274 for ticket #3887 only  
modified one copy of the duplicate code.
