[Dbix-class] find redux

Zbigniew Lukasiak zzbbyy at gmail.com
Mon Feb 18 12:36:08 GMT 2008


On Feb 17, 2008 4:58 PM, Matt S Trout <dbix-class at trout.me.uk> wrote:
> >
> > Now, waiting for this to be committed, here is the problem with the
> > *_or_* methods: Pg will not accept an INSERT with the primary key set
> > to NULL and on the other hand the "find" method will not accept a
> > query without the primary key.
>
> I don't understand why you'd want to find() when you don't have a key to
> find by?
>
> What's your use case for passing undef to find_or_create at all? Surely
> in this case you should just be calling create?

The idea is to have a method that would check the parameters passed to
it and do the right thing.  Of course you can check the parameters
yourself - and then call find or create yourself - but then you don't
need find_or_create.  And if you want to do it in a generic way (lets
say when you write a library) then you'll end up with a function very
similar to find_or_create and with the same problems.

Autoincrement primary keys are the most common case - and it turns out
that find_or_create is useless in that case - because you need to
check the parameters yourself and call create or find.  Sure I can
live without find_or_create - but I believe that such universal
functions, that work regardless of what database you use, what primary
key you use is what adds value to the library.

-- 
Zbigniew Lukasiak
http://perlalchemy.blogspot.com/



More information about the DBIx-Class mailing list