On Fri, Jun 16, 2006 at 03:36:50PM +1000, brett gardner wrote:
> How do I override the result set search?
>
> By overriding the new method for the class object?? eg
>
> package Schema::Foo;
> __PACKAGE__->table('foo');
> ...
>
> sub new {
> #if order_by not set, set it to 'foo';
> }
No, that's overriding the Row class. See DBIx::Class::Cookbook. You
can either create a custom ResultSet class for your object or use
the (experimental) DBIx::Class::ResultSetManager approach, which
lets you override ResultSet methods in your Row class using the
'ResultSet' attribute i.e. something like (untested):
package Schema::Foo;
__PACKAGE__->load_components(qw/ResultSetManager Core/);
__PACKAGE__->table('foo');
# etc ...
sub search : ResultSet
{
my ($self, $cond, $attr) = @_;
$attr->{order_by} ||= 'bar';
$self->next::method($cond, $attr);
}
Cheers,
Gavin
_______________________________________________
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/
Searchable Archive: http://www.mail-archive.com/[email protected]/