[Dbix-class] role of result class?

Matt S Trout dbix-class at trout.me.uk
Wed Mar 8 15:37:13 CET 2006


Michele Beltrame wrote:
> Hello Jess!
> 
>> So if you want to add methods to a search result as a whole, you need to 
>> create your own result_class ..
> 
> I enter the discussion. ;-)
> 
> I'm a Catalyst user and I have some very complex searches I'd like to
> stick into a Model rather than a Controller, i.e a
> "get_events_for_day(day)" for a calendar. When I wa susing Class::DBI I
> just used to extend the class relative to the table with a new method,
> but with DBIx::Class::Schema I'm unsure how to do that. Should I create
> my own result_class in this case, as you say? Also, does this make sense
> or should I stick everything in the Controller (even though I think the
> Model is more appropriate)?

Custom resultset class.

package My::Schema::Foo;

use base qw/DBIx::Class::Core/;

...
__PACKAGE__->resultset_class('My::Schema::Foo::ResultSet');

package My::Schema::Foo::ResultSet;

use base qw/DBIx::Class::ResultSet/;

...

Or as a quicker way, have a look at DBIx::Class::ResultSetManager (which is 
new and not guaranteed perfect but provides a fairly neat shortcut syntax)

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list