Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

[SOLVED] Ordering DBIx::Class joined searches by timestamp

by LunarCowgirl (Sexton)
on Jul 03, 2015 at 02:59 UTC ( [id://1133029]=perlquestion: print w/replies, xml ) Need Help??

LunarCowgirl has asked for the wisdom of the Perl Monks concerning the following question:

Is it not possible to order joined searches by timestamp with DBIx::Class? I have a SQLite table with created and updated columns that are of the type timestamp. I have a search:

sub get_latest_by_category { my ( $self, $id, $rows ) = @_; return $self->search( { 'category.id' => $id, 'me.published' => 1, }, { join => { 'artist_categories' => 'category' }, order_by => { -desc => 'me.created' }, rows => $rows, } ); }

It returns the data sorted by the name column in ascending order, which is the first column after the primary key, rather than by the created column in descending order. I can order by created in non-joined searches, and if I change me.created to another column in the above search, it'll return the results in the correct sort order and direction. It just won't do it with a joined search ordered by a timestamp column.

A DBIC_TRACE shows that it's reading the query correctly "ORDER BY me.created DESC". Is there something special about this type of search? Or if this is a limitation, is there an easy way around it?

UPDATE: Ah, never mind. I discovered where the error was. It was a problem with the test database.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1133029]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found