[Dbix-class] Passing values to a custom join condition

Andrew Beverley andy at andybev.com
Sun Jan 19 17:13:58 GMT 2014


On Thu, 2014-01-09 at 06:56 +0000, Peter Rabbitson wrote:
> On Sun, Jan 05, 2014 at 09:44:13PM +0000, Andrew Beverley wrote:
> > I'm using add_relationship to create a custom join condition, as
> > described at
> > https://metacpan.org/pod/DBIx::Class::Relationship::Base#condition
> > 
> > In a similar vein to the example in the manual, I have created the
> > following relationship:
> > 
> > __PACKAGE__->has_many(
> >   "site_single_tasks",
> >   "Lenio::Schema::Result::SiteTask",
> >   sub {
> >       my $args = shift;
> >       return {
> >         "$args->{foreign_alias}.task_id" =>
> >             { -ident => "$args->{self_alias}.id" },
> >         "$args->{foreign_alias}.site_id" =>
> >             { '=', "100" },
> >       };
> >   },
> >   { cascade_copy => 0, cascade_delete => 0 },
> > );
> > 
> > My question: is it possible for the value "100" in my code above to be a
> > variable, with the value passed from ->search (or otherwise). I can't
> > see anything in the args that are passed to the function that could be
> > used.
> > 
> > The reason I'd like to do this, is that in my join I only want certain
> > values from the table being joined; I want the missing ones to have a
> > value of NULL, which would not be possible with a simple WHERE
> > condition.
> > 
> 
> Sorry for the late reply. The current recommended way to do this is to 
> have the coderef in question refer to a global variable (and throw if 
> the variable has not been local()-set to something before the search() 
> condition is executed).

Thanks, that makes sense for the time being.

> The long term solution hinges on this being implemented: 
> http://lists.scsys.co.uk/pipermail/dbix-class/2014-January/011565.html

But I look forward to that being implemented in the longer term. I did
look at the problem and wonder whether I could contribute myself, but
think it's a bit out of my league at the moment ;-)

Thanks for all the work.

Andy






More information about the DBIx-Class mailing list