[Dbix-class] about "search" and "find" ...

Carl Franks fireartist at gmail.com
Fri Jun 16 16:52:02 CEST 2006

On 16/06/06, Daniel McBrearty <danielmcbrearty at gmail.com> wrote:
> I'm not really getting the difference from reading
> http://search.cpan.org/~jrobinson/DBIx-Class-0.06003/lib/DBIx/Class/ResultSet.pm#METHODS

Note the return values, search() return a resultset whereas find()
returns a single row.

> Also takes an optional key attribute, to search by a specific key or
> unique constraint. For example:
>   my $cd = $schema->resultset('CD')->find(
>     {
>       artist => 'Massive Attack',
>       title  => 'Mezzanine',
>     },
>     { key => 'artist_title' }
>   );
> "
> I don't get this - this is looking for an album where artist and title
> have the given values ... so what is the key doing, in terms of the
> actual query?

Judging by the key name "artist_title", it looks like it's a
multi-column key on both the artist and title columns.
(though in real-life, the artist col would probably be an int,
refering to a seperate Artists table).


More information about the Dbix-class mailing list