[Dbix-class] search vs. find

John Goulah jgoulah at gmail.com
Wed Jun 6 22:19:56 GMT 2007


On 6/5/07, Lee Standen <nom at standen.id.au> wrote:
>
> It comes down to the purpose of the methods...
>
> find() is intended for searches which return only a single result, so it
> makes sense to return a row, rather than a resultset.
>
> search() is intended for searches which return multiple results.
>
> Last I checked, find() needs you to specify your primary keys as the
> search terms, which guarantees uniqueness (primary keys have to be
> unique, remember?).  Note that primary key could be over two or tree
> columns :)
>
> ktnxbye.
>
>
>
>
> John Goulah wrote:
> > On 6/5/07, *Brandon Black* <blblack at gmail.com
> > <mailto:blblack at gmail.com>> wrote:
> >
> >     On 6/5/07, John Goulah <jgoulah at gmail.com
> >     <mailto:jgoulah at gmail.com>> wrote:
> >      > So I've noticed that search returns a "resultset"
> >      > (MyApp::ResultSet::Tablename) and find returns a "row_object"
> >      > (MyApp::Model::MyDB::Tablename).  I suppose this makes some
> >      > sense since search may return many rows while find is designed to
> >     find one
> >      > row.  However it seems that its more useful to deal with the
> >     resultset
> >      > object, for example if I have defined my own custom resultset
> >     functions
> >      > within, I can reuse this returned object to call them, perhaps
> >     even using
> >      > some of the already populated fields as parts of the where clause
> >     (such as a
> >      > primary key like user_id).  Maybe not the best idea, but seems
> >     easier than
> >      > passing the same user_id into each query.   In any case, is there
> >     any way to
> >      > force/cast the "row_object" into a result set, or are we stuck
> >     with only
> >      > using search if we want a ResultSet back?
> >      >
> >
> >     If you want to find a single record, you use ->find(), if you want a
> >     resultset which represents a single record, you use ->search({
> >     pk_colname =3D> "pk_value" });
> >
> >     -- Brandon
> >




Ok, I appreciate the help, but rather than reiterating what I already had in
the initial post as responses, how about a real answer?  Anyway I found the
answer myself, for anyone interested:

>From DBIx::Class::Manual::Cookbook (
http://search.cpan.org/~mstrout/DBIx-Class-0.07000/lib/DBIx/Class/Manual/Co=
okbook.pod#Retrieving_a_row_object
)

  my $schema =3D $cd->result_source->schema;
  my $artist_rs =3D $schema->resultset('Artist');


 Thanks,
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070606/56c=
6c00a/attachment.htm


More information about the Dbix-class mailing list