[Dbix-class] Order by

brett gardner brett at clientcomm.com.au
Fri Jun 16 07:36:50 CEST 2006


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';
}

Cheers,
Brett

Gavin Carr wrote:

>Hi Brett,
>
>On Fri, Jun 16, 2006 at 11:14:05AM +1000, brett gardner wrote:
>  
>
>>Is there anyway in DBIx::Class to set in the table class object the 
>>fields you want the results to be sorted by by default. eg
>>
>>__PACKAGE__->table('foo');
>>__PACKAGE__->add_columns(qw/foo_id foo bar/);
>>__PACKAGE__->sort_column('bar');
>>
>>Or do you have to manually set the order_by field statement everywhere 
>>you try and retrieve these items?
>>    
>>
>
>I don't think there's anything built in for this, but you could just
>override your ResultSet search and insert a default order_by into the 
>attribute hash if one doesn't already exist.
>
>  
>
>>Also, is there an ability to have named groups of columns similar to 
>>Class::DBI? eg
>>
>>__PACKAGE__->add_column_group('menu'=>qw/foo bar/);
>>
>>This would be useful for a default handler to display a menu of items. I 
>>have actually implemented this myself but I don't think I did it in a 
>>very smart or efficient way.
>>    
>>
>
>Yep - see the docs for DBIx::Class::CDBICompat - you want ColumnGroups,
>which allows:
>
>  __PACKAGE__->columns(menu => qw/foo bar/);
>
>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/dbix-class@lists.rawmode.org/
>
>
>  
>

-- 
Brett Gardner
Clientcomm
Phone : 02 9699 1888
Fax   : 02 9318 6499




More information about the Dbix-class mailing list