[Dbix-class] update and join

RAPPAZ Francois francois.rappaz at unifr.ch
Tue Jan 6 08:58:36 GMT 2015


Hi Peter, 

As I said,
$s->resultset('Ddref')->search(
  { 'RefUser.iduser' => 3 },
  { join => 'RefUser' }
)->update({ id_credit => 22 });

Fails since id_credit is in Dduser

Or 
$s->resultset('Ddref')->search(
  { 'RefUser.iduser' => 3 },
  { join => 'RefUser' }
)->update({ 'RefUser.id_credit' => 22 });
Fails also ( Unknown column 'RefUser.id_credit)

But updating a resultset based on Dduser works of course

$s->resultset('Dduser')->search_rs({iduser => $user})->update({id_credit => $value});


Is the update within a resulset based on Ddref possible ? what am I missing then ?

Thanks 

François

> -----Original Message-----
> From: Peter Rabbitson [mailto:rabbit+dbic at rabbit.us]
> Sent: samedi, 20. décembre 2014 16:08
> To: dbix-class at lists.scsys.co.uk
> Subject: Re: [Dbix-class] update and join
> 
> On 11/13/2014 12:34 PM, RAPPAZ Francois wrote:
> > I have two tables joined by a "belongs to" and a "has many"
> relationship
> >        Ddref
> >             idref iduser finished created
> >             n    n--------------+
> >             ^                   ¦
> >             ¦                   ¦RefUser (bt iduser)
> >             ¦UserRef (hm)       ¦
> >             ¦                   ¦
> >             1     1<------------+
> >             Dduser
> >             iduser email id_credit
> >
> > 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'
> >
> 
> Hi Francois,
> 
> I just wanted to check with you whether you ended up with a reasonable
> answer to your question, or if you are still confused.
> 
> Thanks!
> 
> 
> _______________________________________________
> 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 at lists.scsys.co.uk


More information about the DBIx-Class mailing list