From: Matt S Trout Date: Fri, 3 Aug 2007 21:01:49 +0000 (+0000) Subject: add default_resultset_attributes entry to Schema X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e6c747fd70a279e5b97392a266635672f39f7a30;p=dbsrgits%2FDBIx-Class-Historic.git add default_resultset_attributes entry to Schema --- diff --git a/Changes b/Changes index 8635a41..d767232 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for DBIx::Class + - add default_resultset_attributes entry to Schema - optimisation in DBI::Cursor to check software_limit before falling back to base Cursor->all - fix bug with create_multi not inserting non-storage objects diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 64c8e95..8c40b36 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -988,7 +988,11 @@ sub resultset { ) if scalar @_; return $self->resultset_class->new( - $self, $self->{resultset_attributes} + $self, + { + %{$self->{resultset_attributes}}, + %{$self->schema->default_resultset_attributes} + }, ); } diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index a1571bc..67a9593 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -17,6 +17,7 @@ __PACKAGE__->mk_classdata('storage_type' => '::DBI'); __PACKAGE__->mk_classdata('storage'); __PACKAGE__->mk_classdata('exception_action'); __PACKAGE__->mk_classdata('stacktrace' => $ENV{DBIC_TRACE} || 0); +__PACKAGE__->mk_classdata('default_resultset_attributes' => {}); =head1 NAME diff --git a/t/67pager.t b/t/67pager.t index 6abea95..b7bb73f 100644 --- a/t/67pager.t +++ b/t/67pager.t @@ -1,14 +1,12 @@ use strict; use warnings; -use Test::More; +use Test::More qw(no_plan); use lib qw(t/lib); use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 13; - # first page my $it = $schema->resultset("CD")->search( {}, @@ -76,3 +74,11 @@ $it = $schema->resultset("CD")->search( )->search( undef, { order_by => 'title' } ); is( $it->count, 2, "chained searches paging ok" ); + +my $p = sub { $schema->resultset("CD")->page(1)->pager->entries_per_page; }; + +is($p->(), 10, 'default rows is 10'); + +$schema->default_resultset_attributes({ rows => 5 }); + +is($p->(), 5, 'default rows is 5');