[Dbix-class] What should DBIC objects stringify to?

Aran Deltac aran at arandeltac.com
Wed May 3 16:43:13 CEST 2006

On 5/3/06, Matija Grabnar <matija at literal.si> wrote:
> While programming in CDBI I got used to this paradigm:
> $obj = $something->search({whatever});
> if ($obj) {

This would probably fit your needs:

my $resultset = $something->search({whatever});
if ($resultset->count()) {

>     # do something with the result
> } else {
>     # we got an empty result
> }
> In other words, in CDBI results stringify (if that's the wrong word,
> please enlighten me) into undef (or some other false value) if they
> don't contain any elements, and to the primary key otherwise.

This is because the moment you search in CDBI the query is issued to
the database, thus stringifying may return the number of records.  In
DBIC land no query is issued on a search - instead you have to
actually start useing the resultset that is returned before any
queries are run.

> I understand that this is somewhat trickier with DBIC, considering DBIC
> objects can easily have multiple primary keys.

Multiple primary keys should have nothing to do with this.

> But could we still have something resolving to a false value when a
> search returns
> nothing? Or am I missing something in the docs?

Resultsets are more than just an iterator object, they are the heart
and guts of DBIC (IMO).  Resultsets may be created from resultsets,
propogating the parameters and attributes of the query.  So, a
resultset isn't just used for a simple search.


> _______________________________________________
> 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/

More information about the Dbix-class mailing list