[Dbix-class] Unexpected ORDER BY in query

Matt S Trout dbix-class at trout.me.uk
Fri Jan 5 14:37:45 GMT 2007


On 5 Jan 2007, at 14:22, Ben Staude wrote:

> Hi all,
>
> I hope my question can be answered "generally" so I don't have to  
> go too much
> into the details of my dbic setup...
>
> Here's my problem:
> I select rows in a table and use prefetch to also select a has_many
> relationship. The select itself is ok, but it contains an "ORDER BY"
> statement that I can't explain. It orders by the first column of the
> connection table.
>
> I eliminated every order_by in the project's complete source code;  
> it didn't
> help. I don't use sort_column() anywhere.
>
> If I add an order_by to the ResultSet attributes, this column is  
> added to the
> ORDER BY in front of the "unwanted" sort-column.

This is added so the has_many prefetch returns are produced in the  
right order, which makes things much more efficient and allows $rs- 
 >next to work with has_many prefetch. Since your explicit order_by  
happens first, it should make no difference to the results you get,  
it just makes it a lot more efficient for DBIC to get them for you.

-- 
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for  
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for  
details.
+ Help us build a better perl ORM: http://dbix- 
class.shadowcatsystems.co.uk/ +





More information about the Dbix-class mailing list