[Dbix-class] Order by

Gavin Carr gavin at openfusion.com.au
Fri Jun 16 07:59:53 CEST 2006


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





More information about the Dbix-class mailing list