Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

DBIC ordering results by date in a related table

by redlemon (Hermit)
on May 22, 2009 at 12:22 UTC ( #765668=perlquestion: print w/replies, xml ) Need Help??
redlemon has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm struggling to express a query in DBIC. I've got the following situation:

table events { id primary key, name varchar } table sessions { id primary key, event references events(id), starts datetime }

I have the appropriate DBIx classes set up, including the proper has_many() and belongs_to() relationships. So each event can have multiple sessions. I need a list of events, ordered their earliest start date. The SQL for this would be:

select, s.starts from events e join sessions s on = s.event join ( select event, min(starts) as starts from sessions group by event ) as t on s.event = t.event and s.time = t.starts

But how do I convert this to a DBIC expression? I'd appreciate your help


Replies are listed 'Best First'.
Re: DBIC ordering results by date in a related table
by Anonymous Monk on May 22, 2009 at 15:10 UTC
    you can stick to sql :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://765668]
Approved by zwon
[Corion]: Michael_W: $Variables[0] = $Map_Request_Date; $Variables[1] = $Map_Due_Date; ...
[choroba]: ( $Map_Request_Date, $Map_Due_Date,$Map _Cutover_Date,$Map _Complete_Date,$Ma p_Approved_Date) = @Variables;?
[thezip]: something like: $Map_Request = <value>; etc. should work
[Corion]: Duh - I read it backwards. I shouldn't code today I guess ;)
[thezip]: G'day all, BTW!

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (15)
As of 2017-04-27 15:36 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (509 votes). Check out past polls.