[Dbix-class] creating a row that's empty but for an auto-incremented key?

Brett Gardner brett at clientcomm.com.au
Sat Jul 8 02:35:03 CEST 2006


if you do

$foo = $schema->resultset('Foo')->new({});
$foo->bar('bar');
$foo->insert;

The $foo->insert is when the INSERT statement is executed, and it will 
set the primary key column itself.


George Hartzell wrote:

>I'd like to create a row in a table that's empty except for it's
>primary key column (e.g. 'id'), which should be automatically
>generated by PK::Auto.  I go on to possibly insert things into it
>and/or have rows in other tables which have it's id as a foreign key.
>
>I'm using Postgresql on FreeBSD 6.1 and DBIx::Class 0.06003.
>
>The closest thing to the Class::DBI idiom that I know seems to be
>this:
>
>  $foo = $schema->resultset('Foo')->create({});
>
>but that says (retyped by hand and wrapped):
>
>  DBIx::Class::ResultSet::Create(): Error executing 'INSERT INTO 
>    foo () VALUES ()' (): Error syntax error at or near ")" at
>    character 21
>
>and flipping the sql debugging environment variable shows that it is
>try insert "nothing", e.g.
>
>  INSERT INTO foo () VALUES () ()
>
>What's the DBIx::Class idiom/recipe?
>
>Thanks,
>
>g.
>
>_______________________________________________
>List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
>Wiki: http://dbix-class.shadowcatsystems.co.uk/
>IRC: irc.perl.org#dbix-class
>SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
>Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/
>
>
>  
>



More information about the Dbix-class mailing list