[Dbix-class] For a reliable update_or_create we need to make
create( { primary_key => undef, ... } ) work in Pg
Matt S Trout
dbix-class at trout.me.uk
Mon Jan 21 10:27:13 GMT 2008
On Fri, Jan 18, 2008 at 01:05:30PM +0100, Zbigniew Lukasiak wrote:
> I think I have it well documented in the "rs->find finds by all
> columns" thread that find behaviour is rather not reliable when it is
> not fed a unique constraint. By the way here is another question -
> what should happen when you call find with just one of the two fields
> in a composed primary key? Currently it would return just first
> record with that one field set to the searched value, I don't know if
> that is a bug - but it is surprising isn't it?
>
> In fact all of this is not that bad - because it can also be viewed as
> an error on the application side to try to find something without
> supplying a unique condition.
>
> The problem is that update_or_create relies on calling find without a
> unique constraint. And more precisely it needs to do that if you want
> to write a generic handler for updating or creating rows that would
> work for all databases. The reason for that is that $rs->create( {
> primary_key => undef, ... } ) will not work for Pg so when you call
> update_or_create and you have no primary key you need to delete it
> from the query.
I don't understand that. If you don't have a PK value, don't pass the
column. This works perfectly and is orthogonal to your proposed find changes.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the DBIx-Class
mailing list