[Catalyst-commits] r12122 - in
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk: .
lib/CatalystX/CRUD/ModelAdapter t/lib t/lib/MyApp/Controller
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Tue Dec 1 17:08:46 GMT 2009
Author: karpet
Date: 2009-12-01 17:08:46 +0000 (Tue, 01 Dec 2009)
New Revision: 12122
Added:
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp/Controller/Root.pm
Modified:
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/MANIFEST
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp.pm
Log:
release 0.11
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes 2009-12-01 16:58:16 UTC (rev 12121)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes 2009-12-01 17:08:46 UTC (rev 12122)
@@ -33,7 +33,8 @@
* fix ORDER BY via cxc-order so that it actually works, including tests for multi-column sort.
0.10 14 July 2009
- * fix tests so that (a) sql is complete and (b) skip is sqlite3 cmd tool not found
+ * fix tests so that (a) sql is complete and (b) skip if sqlite3 cmd tool not found
-0.11 xxx
- * TODO: fix order_by logic to only prefix 'me.' when column actually exists
+0.11 1 Dec 2009
+ * fix order by logic to check for cxc-m2m param (still a TODO item)
+ * refactor tests to put Root methods in their own controller
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/MANIFEST
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/MANIFEST 2009-12-01 16:58:16 UTC (rev 12121)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/MANIFEST 2009-12-01 17:08:46 UTC (rev 12122)
@@ -11,6 +11,7 @@
t/insertdb.pl
t/lib/MyApp.pm
t/lib/MyApp/Controller/CRUD.pm
+t/lib/MyApp/Controller/Root.pm
t/lib/MyApp/Model/Main.pm
t/lib/MyForm.pm
t/lib/MyModelAdapter.pm
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 2009-12-01 16:58:16 UTC (rev 12121)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm 2009-12-01 17:08:46 UTC (rev 12122)
@@ -246,28 +246,38 @@
}
# ORDER BY
- dump $c->action;
- dump $field_names;
+ #dump $field_names;
if ( exists $query->{sort_by} ) {
$opts{order_by} ||= $query->{sort_by};
# default is to sort by PK, which might not be prefixed.
- my $ss = Sort::SQL->parse($opts{order_by});
- dump $ss;
+ my $ss = Sort::SQL->parse( $opts{order_by} );
+
+ #dump $ss;
my @order_by;
for my $clause (@$ss) {
- if ($clause->[0] !~ m/\./) {
- my $name = "me." . $clause->[0];
- if (grep {$_ eq $name} @$field_names) {
- $clause->[0] = $name;
+ if ( $clause->[0] !~ m/\./ ) {
+
+ if ( $c->req->params->{'cxc-m2m'} ) {
+
+ # TODO m2m
+
}
- next; # TODO skip if not qualified. see how rdbo addresses m2m issue.
+ else {
+
+ # o2m
+ my $name = "me." . $clause->[0];
+ if ( grep { $_ eq $name } @$field_names ) {
+ $clause->[0] = $name;
+ }
+ }
}
- push @order_by, join(' ', @$clause);
+ push @order_by, join( ' ', @$clause );
}
- $opts{order_by} = join(', ', @order_by);
+ $opts{order_by} = join( ', ', @order_by );
}
- dump \%opts;
+
+ #dump \%opts;
$query->{OPTS} = \%opts;
$c->log->debug( "query: " . dump $query ) if $c->debug;
Added: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp/Controller/Root.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp/Controller/Root.pm (rev 0)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp/Controller/Root.pm 2009-12-01 17:08:46 UTC (rev 12122)
@@ -0,0 +1,105 @@
+package MyApp::Controller::Root;
+use strict;
+use warnings;
+use base qw( Catalyst::Controller );
+
+__PACKAGE__->config( namespace => '' );
+
+# mimic testdb.pl from the cookbook
+sub test1 : Local {
+ my ( $self, $c ) = @_;
+
+ my $schema = $c->model('Main')->schema;
+ my $count = 0;
+
+ get_tracks_by_cd( $schema, \$count, 'Bad' );
+ get_tracks_by_artist( $schema, \$count, 'Michael Jackson' );
+
+ get_cd_by_track( $schema, \$count, 'Stan' );
+ get_cds_by_artist( $schema, \$count, 'Michael Jackson' );
+
+ get_artist_by_track( $schema, \$count, 'Dirty Diana' );
+ get_artist_by_cd( $schema, \$count, 'The Marshall Mathers LP' );
+
+ $c->res->body($count);
+}
+
+#################################################################
+## private functions
+
+sub get_tracks_by_cd {
+ my $schema = shift;
+ my $count = shift;
+ my $cdtitle = shift;
+ my $rs
+ = $schema->resultset('Cd')->find( { 'title' => $cdtitle }, )->tracks;
+ while ( my $track = $rs->next ) {
+ $$count++;
+ }
+
+}
+
+sub get_tracks_by_artist {
+ my $schema = shift;
+ my $count = shift;
+ my $artistname = shift;
+ my $rs = $schema->resultset('Artist')->find( { 'name' => $artistname }, )
+ ->cds;
+ while ( my $cd = $rs->next ) {
+ my $tracks = $cd->tracks;
+ while ( my $track = $tracks->next ) {
+ $$count++;
+ }
+ }
+
+}
+
+sub get_cd_by_track {
+ my $schema = shift;
+ my $count = shift;
+ my $tracktitle = shift;
+
+ my $rs = $schema->resultset('Track')->find( { 'title' => $tracktitle } );
+ my $cd = $rs->cds->first;
+ $$count++;
+}
+
+sub get_cds_by_artist {
+ my $schema = shift;
+ my $count = shift;
+ my $artistname = shift;
+
+ my $rs = $schema->resultset('Cd')->search(
+ { 'artist.name' => $artistname },
+ { join => [qw/ artist /],
+ prefetch => [qw/ artist /]
+ }
+ );
+ while ( my $cd = $rs->next ) {
+ $$count++;
+ }
+
+}
+
+sub get_artist_by_track {
+ my $schema = shift;
+ my $count = shift;
+ my $tracktitle = shift;
+
+ my $rs = $schema->resultset('Track')->find( { 'title' => $tracktitle } );
+ my $artist = $rs->cds->first->artist;
+ $$count++;
+}
+
+sub get_artist_by_cd {
+ my $schema = shift;
+ my $count = shift;
+ my $cdtitle = shift;
+
+ my $rs = $schema->resultset('Artist')
+ ->search( { 'cds.title' => $cdtitle }, { join => [qw/ cds /], } );
+ my $artist = $rs->first;
+ $$count++;
+}
+
+1;
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp.pm 2009-12-01 16:58:16 UTC (rev 12121)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp.pm 2009-12-01 17:08:46 UTC (rev 12122)
@@ -6,102 +6,5 @@
__PACKAGE__->setup();
-# mimic testdb.pl from the cookbook
-sub test1 : Local {
- my ( $self, $c ) = @_;
-
- my $schema = $c->model('Main')->schema;
- my $count = 0;
-
- get_tracks_by_cd( $schema, \$count, 'Bad' );
- get_tracks_by_artist( $schema, \$count, 'Michael Jackson' );
-
- get_cd_by_track( $schema, \$count, 'Stan' );
- get_cds_by_artist( $schema, \$count, 'Michael Jackson' );
-
- get_artist_by_track( $schema, \$count, 'Dirty Diana' );
- get_artist_by_cd( $schema, \$count, 'The Marshall Mathers LP' );
-
- $c->res->body($count);
-}
-
-#################################################################
-## private functions
-
-sub get_tracks_by_cd {
- my $schema = shift;
- my $count = shift;
- my $cdtitle = shift;
- my $rs
- = $schema->resultset('Cd')->find( { 'title' => $cdtitle }, )->tracks;
- while ( my $track = $rs->next ) {
- $$count++;
- }
-
-}
-
-sub get_tracks_by_artist {
- my $schema = shift;
- my $count = shift;
- my $artistname = shift;
- my $rs = $schema->resultset('Artist')->find( { 'name' => $artistname }, )
- ->cds;
- while ( my $cd = $rs->next ) {
- my $tracks = $cd->tracks;
- while ( my $track = $tracks->next ) {
- $$count++;
- }
- }
-
-}
-
-sub get_cd_by_track {
- my $schema = shift;
- my $count = shift;
- my $tracktitle = shift;
-
- my $rs = $schema->resultset('Track')->find( { 'title' => $tracktitle } );
- my $cd = $rs->cds->first;
- $$count++;
-}
-
-sub get_cds_by_artist {
- my $schema = shift;
- my $count = shift;
- my $artistname = shift;
-
- my $rs = $schema->resultset('Cd')->search(
- { 'artist.name' => $artistname },
- { join => [qw/ artist /],
- prefetch => [qw/ artist /]
- }
- );
- while ( my $cd = $rs->next ) {
- $$count++;
- }
-
-}
-
-sub get_artist_by_track {
- my $schema = shift;
- my $count = shift;
- my $tracktitle = shift;
-
- my $rs = $schema->resultset('Track')->find( { 'title' => $tracktitle } );
- my $artist = $rs->cds->first->artist;
- $$count++;
-}
-
-sub get_artist_by_cd {
- my $schema = shift;
- my $count = shift;
- my $cdtitle = shift;
-
- my $rs = $schema->resultset('Artist')
- ->search( { 'cds.title' => $cdtitle }, { join => [qw/ cds /], } );
- my $artist = $rs->first;
- $$count++;
-}
-
1;
More information about the Catalyst-commits
mailing list