[Dbix-class] postgresql and serial primary key
Luca Ferrari
fluca1978 at infinito.it
Mon Feb 2 17:02:30 GMT 2015
Hi all,
I'm a problem with PostgreSQL serial field used as keys, and it seems
there's something in DBIx I'm not understanding.
My Result has a definition for the column as follows:
__PACKAGE__->add_columns(
"pk",
{
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
sequence => "tickets_pk_seq",
}, ...
when I want to add a new field I do the following (in a catalyst
application) in the controller;
my $current_ticket = $c->model( 'DB::Ticket' )->find_or_new( { pk => $pk } );
...
$current_ticket->update_or_insert();
the problem is that for a new record the pk field is still null, and
therefore the sequence is not called since the value NULL is placed in
the query.
Moreover, since my Result has has_many objects, the null value is
propagated to the child objects.
Is there a way to auto-query the sequence when the record is going to
be inserted? I don't want to query it always to avoid sequence-holes.
Similarly, I don't want to find_or_create records since the user could
not end inserting it and I would have "blank" tuples.
Suggestions?
Thanks,
Luca
More information about the DBIx-Class
mailing list