[Dbix-class] bug with find_or_new and update_or_insert,
for postgres DB -> work around
Rolf Schaufelberger
rs at plusw.de
Mon Jan 7 08:28:19 GMT 2008
Hi,
On Sunday 06 January 2008 11:13:21 Patrick Weemeeuw wrote:
> Analyzing the problem a bit more, I found out that, in generic terms,
> find_or_new({ pk_col => undef })
> creates an internal row, and that the successive insert fails to substitute
> the pk_col with a value from the sequence, probably because the value has
> been explicitly set.
>
> I'm not sure whether this is a bug or 'as designed'.
>
> Certainly, I can work around this in my application by creating a different
> path in my code depending on whether I have already a value for my PK
> specified or not. But at least one use case for find_or_new &
> update_or_insert, i.e. being able to share the same code in a web
> application both for creation and editing an entry, is not really possible.
>
> thank you for your attention.
>
> -- patrick
I had a similiar issue some days ago, yet with update_or_create
So I have the code :
...
my $fields = {name1=>'Name', city=>'Stuttgart' };
my $addr = $schema->resultset('Address')->update_or_create($fields);
...
and my table has a column id, defined as primary.
Now when I call this code the first time a new record is created and when run
it again it "finds" my previously created record instead creating a new one
as I would expect. The docs says, if no key is given it always checks for a
unique constraint called "primary", which should be there since a primary key
is defined. Even when I write
my $addr = $s->resultset('Address')->update_or_create($fields,
{key=>'primary'});
it finds the old record. So, same conclusion as in your case, not useable
with for edit/update forms. :-(
(Database is postgres)
Rolf Schaufelberger
More information about the DBIx-Class
mailing list