thank you Aaron, that was perfect.
________________________________
From: Aaron Crane <[email protected]>
To: Rajeev Prasad <[email protected]>; DBIx::Class user and developer list
<[email protected]>
Sent: Thursday, October 4, 2012 5:51 AM
Subject: Re: [Dbix-class] DBIX, row update problem
Rajeev Prasad <[email protected]> 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/_______________________________________________
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/[email protected]