[Dbix-class] Joining the same table several times with different conditions each join

Karen Etheridge perl at froods.org
Sat May 17 17:00:57 GMT 2014


On Sat, May 17, 2014 at 11:01:59AM +0100, Andrew Beverley wrote:
> I'd like to join the same table multiple times, with different
> conditions each join (and a variable number of joins).

If you define each of your join permutations as a relationship, you can
bring in the joins using that/those relationship name(s):

$rs->search({ ... }, { join => [ 'rel1', 'rel2', ... ] })

https://metacpan.org/pod/DBIx::Class::ResultSet#join

> Of course, the table could be designed with multiple columns for each of
> the values (surname and firstname being just 2 examples), but these are
> not known at the time of coding and are configurable by the application.

You can dynamically add relationship definitions at runtime.  Just keep the
rel names around in a local variable or attribute for later use.

Sorry if I am missing something complicated that would prevent this from
working -- as it seems pretty straightforward to me! :)





More information about the DBIx-Class mailing list