I tried my $newid = $c->model( q{MyAppDB::MyTable}
)->result_source->storage->last_insert_id(); and it gave me zero, so I'm
not sure how to proceed.
On 10/12/2007, Martin Ellison <[EMAIL PROTECTED]> 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.
>
> On 09/12/2007, Carl Franks <[EMAIL PROTECTED]> wrote:
> >
> > On 09/12/2007, Martin Ellison <[EMAIL PROTECTED]> wrote:
> > > Sorrry, this is another newbie question.
> > >
> > > I am using HTML::Widget and DBIx::Class to do simple CRUD on some
> > MySQL
> > > tables. I have defined an auto-increment primary key on one of my
> > tables,
> > > and I want to use an HTML form to populate and create a new object. I
> > then
> > > want to retrieve the newly-generated key.
> > >
> > > Sup[pose the SQL has:
> > >
> > > CREATE TABLE mytable (
> > > mytable_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
> > > title VARCHAR(64) NOT NULL,
> > > date VARCHAR(10) NOT NULL,
> > > PRIMARY KEY (mytable_id);
> > >
> > > Having read the examples, I thought that all I had to do is:
> > >
> > > my $obj =
> > > $c->model(q{MyAppDB::MyTable})->new({});
> > > $obj->populate_from_widget($result);
> > > my $newid = $obj->mytable_id;
> > >
> > > but I am finding that the generated SQL is in fact setting the key
> > field to
> > > zero, and then the last line of the above code is getting an undefined
> > value
> > > back.
> >
> > I can't remember for sure how populate_from_widget() works, but I
> > suspect that you've a field in your form corresponding to the table's
> > 'id' column. If that's empty, populate_from_formfu() may be trying to
> > blank that column (""), and mysql's converting it to a zero.
> > You can see that exact SQL that's being issued, by setting the
> > environment variable DBIC_TRACE=1
> > If this is new development, HTML::Widget is deprecated in favour of
> > HTML::FormFu.
> > If you decide to look at HTML::FormFu, take note that
> > DBIx::Class::HTML::FormFu is about to be replaced by
> > HTML::FormFu::Model::DBIC, which is still in svn, and will be released
> > to cpan at some point this month.
> >
> > Cheers,
> > Carl
> >
> > _______________________________________________
> > List: [email protected]
> > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> > Searchable archive:
> > http://www.mail-archive.com/[EMAIL PROTECTED]/
> > Dev site: http://dev.catalyst.perl.org/
> >
>
>
>
> --
> Regards,
> Martin
> ([EMAIL PROTECTED])
> IT: http://methodsupport.com Personal: http://thereisnoend.org
>
--
Regards,
Martin
([EMAIL PROTECTED])
IT: http://methodsupport.com Personal: http://thereisnoend.org
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Dev site: http://dev.catalyst.perl.org/