[Dbix-class] creating a row that's empty but for an auto-incremented key?
David Kamholz
davekam at pobox.com
Sat Jul 8 06:35:52 CEST 2006
The example Brett Gardner gave is equivalent to ->create({ bar =>
'bar' }). create() is just new() followed by insert. The issue of
wanting to insert a row with *no* values specified is a more general
one, however. In many cases it's probably bad design to need to do
something like that. But the reason it doesn't work is, first of all,
that SQL::Abstract doesn't give the right syntax for it, and secondly
-- there doesn't seem to be a single "right syntax" for it. "INSERT
INTO foo;" doesn't work for all databases. Some allow "INSERT INTO
foo DEFAULT VALUES;", but I believe that produces an error in mysql.
So we haven't found a general solution yet which is the right way of
handling it.
Dave
On Jul 8, 2006, at 3:42 AM, George Hartzell wrote:
> Brett Gardner writes:
>> if you do
>>
>> $foo = $schema->resultset('Foo')->new({});
>> $foo->bar('bar');
>> $foo->insert;
>
> Thanks, that should work for what I'm trying to do.
>
> Even with this approach, it's still not possible to insert a row in
> which all of the columns except the primary key are non-existent/NULL
> and have the key be automagically generated via PK::Auto, right?
>
> Thanks again,
>
> g.
More information about the Dbix-class
mailing list