[Catalyst-commits] r8300 - in
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk: .
lib/CatalystX/CRUD/ModelAdapter t
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Wed Aug 27 04:36:31 BST 2008
Author: karpet
Date: 2008-08-27 04:36:31 +0100 (Wed, 27 Aug 2008)
New Revision: 8300
Modified:
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/01-dbic.t
Log:
0.05 release
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes 2008-08-27 03:34:59 UTC (rev 8299)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes 2008-08-27 03:36:31 UTC (rev 8300)
@@ -15,6 +15,8 @@
0.04 24 Aug 2008
* switch to DBIx::Class::RDBOHelpers for rel introspection.
+0.05 26 Aug 2008
+ * fix ORDER BY feature and override make_sql_query()
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm 2008-08-27 03:34:59 UTC (rev 8299)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm 2008-08-27 03:36:31 UTC (rev 8300)
@@ -10,7 +10,7 @@
use Carp;
use Data::Dump qw( dump );
-our $VERSION = '0.04';
+our $VERSION = '0.05';
=head1 NAME
@@ -100,12 +100,10 @@
sub search {
my ( $self, $controller, $c, @arg ) = @_;
my $query = shift(@arg) || $self->make_query( $controller, $c );
- my @q;
- push( @q, { @{ $query->{query} } } );
- push( @q, $controller->model_meta->{resultset_opts} )
- if $controller->model_meta->{resultset_opts};
- my @rs = $c->model( $self->model_name )
- ->resultset( $self->_get_moniker( $controller, $c ) )->search(@q);
+ my @rs
+ = $c->model( $self->model_name )
+ ->resultset( $self->_get_moniker( $controller, $c ) )
+ ->search( $query->{WHERE}, $query->{OPTS} );
return wantarray ? @rs : \@rs;
}
@@ -128,15 +126,10 @@
sub iterator {
my ( $self, $controller, $c, @arg ) = @_;
my $query = shift(@arg) || $self->make_query( $controller, $c );
- my @q;
- push( @q, { @{ $query->{query} } } );
- push( @q, $controller->model_meta->{resultset_opts} )
- if $controller->model_meta->{resultset_opts};
-
- #warn "query: " . dump \@q;
-
- my $rs = $c->model( $self->model_name )
- ->resultset( $self->_get_moniker( $controller, $c ) )->search(@q);
+ my $rs
+ = $c->model( $self->model_name )
+ ->resultset( $self->_get_moniker( $controller, $c ) )
+ ->search( $query->{WHERE}, $query->{OPTS} );
return $rs;
}
@@ -149,12 +142,9 @@
sub count {
my ( $self, $controller, $c, @arg ) = @_;
my $query = shift(@arg) || $self->make_query( $controller, $c );
- my @q;
- push( @q, { @{ $query->{query} } } );
- push( @q, $controller->model_meta->{resultset_opts} )
- if $controller->model_meta->{resultset_opts};
return $c->model( $self->model_name )
- ->resultset( $self->_get_moniker( $controller, $c ) )->count(@q);
+ ->resultset( $self->_get_moniker( $controller, $c ) )
+ ->count( $query->{WHERE}, $query->{OPTS} );
}
=head2 make_query( I<controller>, I<context> [, I<field_names> ] )
@@ -171,14 +161,56 @@
my $field_names = shift
|| $self->_get_field_names( $controller, $c );
- # TODO sort order and limit/offset support
- # it's already in $q but need DBIC syntax
+ my $query = $self->make_sql_query( $controller, $c, $field_names ) || {};
+ my %dbic = ( query => $query );
+
+ # WHERE
+ $dbic{WHERE} = { @{ $query->{query} } };
+
+ my %opts;
+
+ # PREFETCH, etc.
+ if ( $controller->model_meta->{resultset_opts} ) {
+ %opts = %{ $controller->model_meta->{resultset_opts} };
+ }
+
+ # ORDER BY
+ if ( exists $query->{order_by} ) {
+ $opts{order_by} ||= $query->{order_by};
+ }
+
+ $dbic{OPTS} = \%opts;
+
+ #carp "query: " . dump \%dbic;
+
+ return \%dbic;
+}
+
+=head2 make_sql_query( I<controller>, I<context>, I<field_names> )
+
+Override method in CatalystX::CRUD::Model::Utils to mimic
+ACCEPT_CONTEXT by setting I<context> in $self.
+
+Otherwise, acts just like CatalystX::CRUD::Model::Utils->make_sql_query().
+
+=cut
+
+sub make_sql_query {
+ my $self = shift;
+ my $controller = shift;
+ my $c = shift;
+ my $field_names = shift;
+
# Model::Utils (make_sql_query) assumes ACCEPT_CONTEXT accessor
$self->{context} = $c;
weaken( $self->{context} );
- return $self->make_sql_query($field_names) || {};
+ my $q = $self->next::method($field_names);
+
+ #carp "make_sql_query : " . dump $q;
+
+ return $q;
}
=head2 search_related( I<controller>, I<context>, I<obj>, I<relationship> [, I<query> ] )
@@ -200,33 +232,19 @@
sub search_related {
my ( $self, $controller, $c, $obj, $rel, $query ) = @_;
$query ||= $self->make_query( $controller, $c );
- my @q;
- push( @q, { @{ $query->{query} } } );
- push( @q, $controller->model_meta->{resultset_opts} )
- if $controller->model_meta->{resultset_opts};
- return [ $obj->$rel->search(@q) ];
+ return [ $obj->$rel->search( $query->{WHERE}, $query->{OPTS} ) ];
}
sub iterator_related {
my ( $self, $controller, $c, $obj, $rel, $query ) = @_;
$query ||= $self->make_query( $controller, $c );
- my @q;
- push( @q, { @{ $query->{query} } } );
- push( @q, $controller->model_meta->{resultset_opts} )
- if $controller->model_meta->{resultset_opts};
-
- #warn "query: " . dump \@q;
- return scalar $obj->$rel->search(@q);
+ return scalar $obj->$rel->search( $query->{WHERE}, $query->{OPTS} );
}
sub count_related {
my ( $self, $controller, $c, $obj, $rel, $query ) = @_;
$query ||= $self->make_query( $controller, $c );
- my @q;
- push( @q, { @{ $query->{query} } } );
- push( @q, $controller->model_meta->{resultset_opts} )
- if $controller->model_meta->{resultset_opts};
- return $obj->$rel->count(@q);
+ return $obj->$rel->count( $query->{WHERE}, $query->{OPTS} );
}
=head2 add_related( I<controller>, I<context>, I<obj>, I<rel_name>, I<foreign_value> )
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/01-dbic.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/01-dbic.t 2008-08-27 03:34:59 UTC (rev 8299)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/01-dbic.t 2008-08-27 03:36:31 UTC (rev 8300)
@@ -38,7 +38,7 @@
POST(
'/crud/0/save',
[ title => 'Something New, Something Blue',
- trackid => 0
+ trackid => 8
]
)
),
More information about the Catalyst-commits
mailing list