[Dbix-class] Useless uses of search

Jonathan Rockway jon at jrock.us
Tue Mar 25 02:26:16 GMT 2008


Hi all,

In the last few days, I've noticed people posting code examples like:

  my $count = $schema->resultset('Foo')->search->count;

or

  my @all = $schema->resultset('Foo')->search(
      undef,
      {}
  )->all;

I don't think there's any reason to do this.  $schema->resultset('Foo')
returns the same resultset that the empty search does, so you could have
just called "count" or "all" without having done the search.

Finally, for those using Catalyst, keep in mind that
$c->model('DBIC::Foo') is basically the same as
$c->model('DBIC')->resultset('Foo'), so there's no need to add an extra
search in this case either.

Regards,
Jonathan Rockway

-- 
print just => another => perl => hacker => if $,=$"



More information about the DBIx-Class mailing list