[Dbix-class] LEFT JOIN with an "OR"

Cory Watson jheephat at gmail.com
Tue Jun 10 00:32:56 BST 2008


On Mon, Jun 9, 2008 at 6:22 PM, J. Shirley <jshirley at gmail.com> wrote:

>
> SELECT
>   `me`.pk1, `me`.name, `me`.dt_created,     `discussable`.*
> FROM
>   `threads` `me`
> LEFT JOIN `discussable_threads` `discussable_threads` ON
>     ( ( `discussable_threads`.`thread_pk1` =3D `me`.`parent_pk1` ) OR (
> `discussable_threads`.`thread_pk1` =3D `me`.`pk1` ) )
> LEFT JOIN `discussables` `discussable` ON ( `discussable`.`pk1` =3D
> `discussable_threads`.`discussable_pk1` )
> LEFT JOIN `topics` `topics` ON ( `topics`.`discussable_pk1` =3D
> `discussable`.`pk1` );
>

My initial suggestion was something like:
if($condition_one) {
  $rs =3D $rs->search(undef, { join =3D> 'rel_1' });
} else {
  $rs =3D $rs->search(undef, { join =3D> 'rel_2' });
}

But this would require an extra query to ascertain the condition instead of
doing it in the join... :/

Assuming I'm not missing something obvious, I'm not even sure what the
syntax for that should look like if the feature was to be added.

-- =

Cory 'G' Watson
http://www.onemogin.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080609/a37=
ac7ec/attachment.htm


More information about the DBIx-Class mailing list