[Dbix-class] Passing values to a custom join condition
Peter Rabbitson
rabbit+dbic at rabbit.us
Thu Jan 9 06:56:51 GMT 2014
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).
The long term solution hinges on this being implemented:
http://lists.scsys.co.uk/pipermail/dbix-class/2014-January/011565.html
Cheers!
More information about the DBIx-Class
mailing list