[Catalyst] update record with unique ID
Michael Higgins
mhiggins at banfieldgroup.com
Mon Apr 9 21:28:30 GMT 2007
> -----Original Message-----
> From: Christopher H. Laco [mailto:claco at chrislaco.com]
>
> Michael Higgins wrote:
> > Hello, Cat-list-ers,
> >
> > Here's a pared-down version of my question, hoping it's an easy one:
> >
> > ERROR:
> > "DBIx::Class::ResultSet::update(): Error executing 'UPDATE ...
> > Duplicate entry '140949' for key 1 at
> >
> > QUESTION:
> > How do we specify UPDATE ... blah WHERE (ID='UNIQUE')
> >
> > CODE:
> > my $result = [$c->model('WhateverDB::Whatever')->update({id =>
> > $id},{ this=>that, another=>something,
> > });]
> >
> > How to update with the unique column... or do I just have to delete
> > the old record and insert a new one from scratch?
> Does not compute.
Sorry. My bad -- I guess my failing code is misleading.
>
> First, I'm going to assume id is your primary key. Why would
> you want to change that?
I don't. :(
>
> Second, based on the error you've provided you already have
> another record with the same $id you're trying to update this
> record to...
>
Right. I want to update the record as defined by that primary key.
I guess I found the answer:
->update_or_create({
Seems to do the trick, checking for unique and updating with other values
posted. Too easy, as usual. ;-)
Cheers,
--
Michael Higgins
More information about the Catalyst
mailing list