[Catalyst] model update

Matt S Trout dbix-class at trout.me.uk
Sat Mar 8 16:35:24 GMT 2008


On Mon, Feb 25, 2008 at 12:56:39PM -0800, Jennifer Ahn wrote:
> hello!
> 
> i'm writing my first controller method to update the database using the 
> catalyst model, but  i seem to have the syntax for that all wrong.
> 
>    my $obj = $c->model ('MyAppDB::Student')->update (
>        { name => $name     },
>        { id => $id}
>        );
> 
> I'm updating the name field where the id field is given for the model 
> called Student.  i'm not sure why, but the code above updates ALL row 
> name fields, not just rows with the particular id.

Read the DBIx::Class::ResultSet docs - update only takes one argument, the
parameters to update with.

If you want to restrict the query, call it on a row object or on a resultset
you've already restricted using search().

If you have any more questions, please ask on the DBIx::Class list.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list