<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Lucida Grande; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Lucida Grande; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Lucida Grande; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Lucida Grande; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Lucida Grande; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Lucida Grande; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; ">Hi Martin,</span></span></span></span></span></span></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">You might check to make sure that you are loading PK::Auto in MyAppDB::MyTable:</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"># ...</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><div>use base 'DBIx::Class';</div><div>__PACKAGE__-&gt;load_components("PK::Auto", "Core");</div><div>__PACKAGE__-&gt;table("mytable");</div><div><br class="webkit-block-placeholder"></div><div># then make sure you declare the primary key later on...</div><div>__PACKAGE__-&gt;set_primary_key("mytable_id");</div><div><br></div><div><br class="webkit-block-placeholder"></div><div>All the best,</div><div>Paul</div><div><br class="webkit-block-placeholder"></div></span></font></div><br><div><div>On 9 Dec 2007, at 6:20 AM, Martin Ellison wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Sorrry, this is another newbie question.<br><br>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. <br><br>Sup[pose the SQL has:<br><br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">CREATE TABLE mytable (</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        mytable_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">       title VARCHAR(64) NOT NULL,</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">       date VARCHAR(10) NOT NULL,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">       PRIMARY KEY (mytable_id);</span> <br></div><br>Having read the examples, I thought that all I had to do is:<br><br><span style="font-family: courier new,monospace;">            my $obj = $c-&gt;model(q{MyAppDB::MyTable})-&gt;new({});</span><br style="font-family: courier new,monospace;"> <span style="font-family: courier new,monospace;">            $obj-&gt;populate_from_widget($result);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            my $newid = $obj-&gt;mytable_id; </span><br><br>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.<br><br>But then I have not actually told my DBIx::Class package for the table that the column is autoincrement -- do I need to do this and if so how? <br clear="all"><br>-- <br>Regards,<br>Martin<br>(<a href="mailto:m.e@acm.org">m.e@acm.org</a>)<br>IT: <a href="http://methodsupport.com">http://methodsupport.com</a> Personal: <a href="http://thereisnoend.org">http://thereisnoend.org </a><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">List: <a href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Searchable archive: <a href="http://www.mail-archive.com/catalyst@lists.rawmode.org/">http://www.mail-archive.com/catalyst@lists.rawmode.org/</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Dev site: <a href="http://dev.catalyst.perl.org">http://dev.catalyst.perl.org</a>/</div> </blockquote></div><br></body></html>