[Dbix-class] how to use a complex query in DBIx::Class

Jess Robinson castaway at desert-island.demon.co.uk
Tue Dec 26 23:23:59 GMT 2006



On Tue, 26 Dec 2006, Wan wrote:

> Like this
>
> SELECT boards.*, hiddenboards.userId IS NOT NULL AS hidden
> FROM boards LEFT JOIN hiddenboards
> ON hiddenboards.userId = '3'
> AND hiddenboards.boardId = boards.id
> WHERE boards.active = 1
> ORDER BY pos;
>
> I want to use this query in DBIx::Class, but...
>

$schema->resultset('boards')->search({
   'hiddenboards.userId' => 3,
   'me.active' => 1,
}, {
   'join' => 'hiddenboards',
   '+select' => [ 'hiddenboards.userId' ],
   '+as' => [ 'hidden' ],
   'order_by' => [ 'pos' ],
})


.. and set up the relationship between board and hiddenboards to use an 
inner join, not a left join.

I've not seen the syntax "SELECT .. hiddenboards.userId IS NOT NULL as 
hidden" .. it's odd, why not use the proper join type?

Jess



More information about the Dbix-class mailing list