[Dbix-class] DBIX, row update problem

Rajeev Prasad rp.neuli at yahoo.com
Thu Oct 4 16:45:46 GMT 2012


thank you Aaron, that was perfect.



________________________________
 From: Aaron Crane <dbix-class at aaroncrane.co.uk>
To: Rajeev Prasad <rp.neuli at yahoo.com>; DBIx::Class user and developer list=
 <dbix-class at lists.scsys.co.uk> =

Sent: Thursday, October 4, 2012 5:51 AM
Subject: Re: [Dbix-class] DBIX, row update problem
 =

Rajeev Prasad <rp.neuli at yahoo.com> wrote:
> I am only intending to update a column in a row based on 'item' value. It=
em
> value is unique constraint column.
>
> DBIx code:
>
>=A0 =A0  $schema->resultset('Itemlist')->update(
>=A0 =A0  {
>=A0 =A0 =A0 =A0  item =3D> $item,
>=A0 =A0 =A0 =A0  item_comment =3D> $mycomments
>=A0 =A0  },
>=A0 =A0  {key =3D>'item'}=A0 =A0 #uniq constraint on item
>=A0 =A0  );

The "update" method on a resultset only accepts one argument, and that
argument specifies what updates are to be applied to the rows that
would be matched by that resultset.=A0 So this code is trying to update
the "item" and "item_comment" columns in *every* Itemlist row.

If I understand your goal, you're trying to update the "item_comment"
column in the (unique) row where the "item" column has the value
$item.=A0 That's done by constraining the resultset to be updated:

=A0 =A0 $schema->resultset('Itemlist')
=A0 =A0 =A0 =A0 =A0  ->search({ item =3D> $item })
=A0 =A0 =A0 =A0 =A0  ->update({ item_comment =3D> $mycomments });

That is, the "search" first restricts the resultset to consider only
rows whose "item" column is $item; then the "update" updates the
"item_comment" for any matching row.=A0 (Which, in this case, should be
precisely one row.)

Does that help?

-- =

Aaron Crane ** http://aaroncrane.co.uk/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20121004/b03=
1e68d/attachment.htm


More information about the DBIx-Class mailing list