Thanks for replying !

So it's a feature, not a bug ?

In mysql, I can execute 
"update `ddrefs` inner join `ddusers` using (iduser) set id_credit = 22 WHERE 
ddrefs.iduser = 3"

It would have been nice to have the same thing working with DBIC: the update 
being possible on a resultset derived from Ddref.

Best

François




> -----Original Message-----
> From: Peter Rabbitson [mailto:rabbit+d...@rabbit.us]
> Sent: jeudi, 13. novembre 2014 22:15
> To: Class user and developer list; Darius Jokilehto
> Subject: Re: [Dbix-class] update and join
> 
> 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
> 
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-
> cl...@lists.scsys.co.uk

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to