[Dbix-class] update and join
RAPPAZ Francois
francois.rappaz at unifr.ch
Thu Nov 13 13:31:36 GMT 2014
Oh thanks, and sorry my message was wrong the RefUser relationship is in Ddref.pm not in Dduser.pm
But my code is correct for that. So again:
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
idref is a primary key for Ddref
iduser is a pk for Dduser
** In Ddref.pm **
__PACKAGE__->belongs_to(RefUser=> 'Dbc::Schema::Result::Dduser', {'foreign.iduser' => 'self.iduser'});
In Dduser.pm
__PACKAGE__->has_many(UserRef => 'Dbc::Schema::Result::Ddref', {'foreign.iduser' => 'self.iduser'});
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 ?
Thanks
François
> -----Original Message-----
> From: Darius Jokilehto [mailto:dariusjokilehto at yahoo.co.uk]
> Sent: jeudi, 13. novembre 2014 13:46
> To: DBIx::Class user and developer list
> Subject: Re: [Dbix-class] update and join
>
> On Thursday, 13 November 2014, 11:36, RAPPAZ Francois
> <francois.rappaz at unifr.ch> 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
> >
> >idref is a primary key for Ddref
> >iduser is a pk for Dduser
> >
> >In Dduser.pm
> >__PACKAGE__->belongs_to(RefUser=> 'Dbc::Schema::Result::Dduser',
> {'foreign.iduser' => 'self.iduser'});
>
> >
>
> This relationship is incorrect - it's pointing to itself.
>
> Hope that helps,
>
> Darius
>
> _______________________________________________
> 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