[Dbix-class] Return value of DBIx::Class::ResultSet::find()

SHAD0WRUNNER at gmx.de SHAD0WRUNNER at gmx.de
Mon May 14 14:14:15 GMT 2007


-------- Original-Nachricht --------
Datum: Mon, 14 May 2007 12:40:03 +0100
Von: Matt S Trout <dbix-class at trout.me.uk>
An: dbix-class at lists.rawmode.org
Betreff: Re: [Dbix-class] Return value of DBIx::Class::ResultSet::find()

> On Mon, May 14, 2007 at 09:57:24AM +0200, Bernhard Graf wrote:
> > Matt S Trout wrote:
> > 
> > > >   do_something($alpha, $rs->find($id), $omega);
> > >
> > > I always do
> > >
> > > if (my $obj = $rs->find(...)) {
> > >
> > > for clarity.
> > 
> > You mean you'd do:
> > 
> >   if (my $obj = $rs->find(...)) {
> >      do_something($alpha, $obj, $omega);
> >   } else {
> >      do_something($alpha, $obj, $omega);
> >   }
> 
> I can't really see somewhere I'd have an API that wanted that, to be
> honest.
> 
> Optional parameters in the middle of the argument list strike me as a
> design smell.
> 
> > > Opinions welcome, I'm not -overly- troubled either way although by
> > > default I'd say the current conceptual consistency is the correct
> > > answer.
> > 
> > At least documentation should clarify the fact, that find() returns a 
> > list of row objects, that either has 1 or 0 elements.
> 
> A doc patch is definitely in order whether we change the behaviour or not.
> 
> My worry is people doing if and getting the return in list context, hence
> seeing a returned undef as true, but equally I can see the convenience
> value
> of changing the behaviour.

Maybe you can migrate softly. I would first use a nother
attr for find, find_or_create and update_or_create like:

my $cd = $schema->resultset('CD')->find('Massive Attack', 'Mezzanine', {
    key => 'cd_artist_title',
    no_list_context => 1,
});

If someone doesn't use the attr no_list_context you have
the possibility to output a warning message "Bla, Bla, Bla
is deprecated ... Bla,Bla, Bla"

Or do it like ruby/rails throw an exception when you don't
find a record by it's primary-key. When I search a primary
key and expect not to find it then it is a search- und not
a find-operation. 

> 
> C'mon people, pitch in with arguments and opinions :)

I haven't expected a list-context by reading the doc's.


> 
> -- 
>       Matt S Trout       Need help with your Catalyst or DBIx::Class
> project?
>    Technical Director    Want a managed development or deployment
> platform?
>  Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a
> quote
> http://chainsawblues.vox.com/            
> http://www.shadowcatsystems.co.uk/ 
> 
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
> http://www.mail-archive.com/dbix-class@lists.rawmode.org/

-- 
FastJack

Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger



More information about the Dbix-class mailing list