[Dbix-class] LEFT OUT JOIN with custom condition/bind value

Aaron Trevena aaron.trevena at gmail.com
Sun Nov 25 21:40:19 GMT 2012


On 25 November 2012 15:27, Peter Rabbitson <rabbit+dbic at rabbit.us> wrote:
> On Sat, Nov 24, 2012 at 04:26:37PM +0100, Sven Eppler wrote:
>> I know about the CODEREF-Option for defining Relationship-Conditions.
>> But they don't seem to solve my problem, right?
>
> Not entirely. The coderef is invoked every time a query is generated,
> and the contents of the coderef are made of perl ;)
>
> So the short-term ugly-as-fuck-but-usable solution is:
>
> ...->has_many(... sub {
>   my $varcond = $My::Secret::Global::varcond
>     or die 'You forgot to set $My::Secret::Global::varcond';
>   ...
> });
>
> and then:
>
> my @res = do {
>   local $My::Secret::Global::varcond = 42;
>   $rs->search(...)->all;
> };
>
> Long term the plan is to have something along these lines[1]. The reason
> this is not yet imlemented is the usual - tuits. It is also not a trivial
> task as the underpinnings are not yet smart eniough to handle something
> of this complexity.

Presumably you could use a method in the resultset to take an arg and
wrap it transparently so you never see the fugly in the rest of your
code?

A

-- 
Aaron J Trevena, BSc Hons
http://www.aarontrevena.co.uk
LAMP System Integration, Development and Consulting



More information about the DBIx-Class mailing list