[Dbix-class] update and join
Peter Rabbitson
rabbit+dbic at rabbit.us
Thu Nov 13 21:14:31 GMT 2014
On 11/13/2014 02:31 PM, RAPPAZ Francois wrote:
> ...
> I would like to update the field id_credit in Ddref :
> my $href2 = {
> '+select' => [ 'RefUser.id_credit', 'RefUser.email'],
> '+as' => [qw/id_credit email/],
> order_by => 'created',
> join => ['RefUser']};
>
> my $href = {idref => 24 };
> my $rs1 = $s->resultset('Ddref')->search_rs($href, $href2); my $row = $rs1->single;
> $row->set_column('id_credit' => 28);
> $row->update();
>
> But update fails with since the sql is
> UPDATE ddrefs SET id_credit = ? WHERE ( idref = ? )" with ParamValues: 0=28, 1='24'
>
> Obviously the join is lost. What am I missing ?
$row does not represent a "row". It represents an item from the
ResultSource of DDrefs. This is where your confustion is coming from -
you assumed that a thing that comes from a $resultset is a
representation of the "row that came off the cursor after all JOINs put
together". This is an implementation detail, which only bled through
because you used the advanced +select/+as options.
In any case - any ->update/->delete/->copy call on a *Result* object
will only operate on the table corresponding to the *ResultSource* of
the *Result* you are operating on.
Please feel free to ask additional question if the above isn't entirely
clear.
Cheers
More information about the DBIx-Class
mailing list