[Dbix-class] DBIX, row update problem

Aaron Crane dbix-class at aaroncrane.co.uk
Thu Oct 4 10:51:09 GMT 2012


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

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.  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.  That's done by constraining the resultset to be updated:

    $schema->resultset('Itemlist')
           ->search({ item => $item })
           ->update({ item_comment => $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.  (Which, in this case, should be
precisely one row.)

Does that help?

-- 
Aaron Crane ** http://aaroncrane.co.uk/



More information about the DBIx-Class mailing list