[Dbix-class] update and join

Peter Rabbitson rabbit+dbic at rabbit.us
Mon Jan 19 15:03:52 GMT 2015


On 01/06/2015 09:58 AM, RAPPAZ Francois wrote:
> Hi Peter,
>
> As I said,
> $s->resultset('Ddref')->search(
>    { 'RefUser.iduser' => 3 },
>    { join => 'RefUser' }
> )->update({ id_credit => 22 });

You are missing that

$s->resultset('Ddref')->search(
     { 'RefUser.iduser' => 3 },
     { join => 'RefUser' }
);

Does not return you a "synthetic" resultset combining both Ddref and the 
Dduser sources. The result of this ->search is *still* a resultset 
pointing to Ddref alone. This is a core design consideration within DBIC 
- a resultset only points to one RDBMS-side source. Therefore any 
->delete/->update/->create operations work on that source alone, and 
nothing else.

The only way to update a field in a source *related* to the source you 
started from is to "switch" the current scope via search_related:


$s->resultset('Ddref')
    ->search_related('RefUser')
     ->search({ 'RefUser.iduser' => 3 })
      ->update({id_credit => 22 });


Is this more helpful?



More information about the DBIx-Class mailing list