[Catalyst] How to insert from form to MySQL with autoincrement primary key?

Carl Franks fireartist at gmail.com
Sun Dec 9 17:45:08 GMT 2007


On 09/12/2007, Martin Ellison <m.e at acm.org> wrote:
> Yes, I had a form field with the same name as the table key, because, when I
> do an update on an existing object, I want to save its key value somewhere.
> ...I've put in a test, so it only includes the field when I want to d an
> update. So now it is formulating the INSERT without the key field, which is
> good. However $obj->id is returning zero, implying that the model is not
> being updated after the insert.
>
> So now I am trying to work out how to get the last insert id. I think if I
> can retrieve the relevant DBIx::Schema I should be able to  use
> $schema->storage->last_input_id, but I'm still trying to
> find out  how to get to the schema.
>
> As to the latest in Catalyst modules, I was using what the documentation
> recommended. I don't want to rewrite everything in another module now.

That's fair enough, as long as you know it's not being maintained by anyone.

Did you turn on DBIC's tracing to see exactly what's going on in the SQL?
$obj->id() should work fine, without having to use last_insert_id.

Carl



More information about the Catalyst mailing list