[Catalyst-commits] r8267 - in
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk: .
lib/CatalystX/CRUD/ModelAdapter t t/MyDB/Main t/lib
t/lib/MyApp/Controller
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Sun Aug 24 07:50:58 BST 2008
Author: karpet
Date: 2008-08-24 07:50:58 +0100 (Sun, 24 Aug 2008)
New Revision: 8267
Modified:
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/MANIFEST
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Makefile.PL
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/01-dbic.t
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Artist.pm
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Cd.pm
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/CdTrackJoin.pm
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Track.pm
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/insertdb.pl
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp.pm
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp/Controller/CRUD.pm
Log:
switch to RDBOHelpers and release 0.04
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Changes 2008-08-24 06:50:58 UTC (rev 8267)
@@ -7,9 +7,16 @@
* fix bug in order of params to make_query()
* add example app in t/example/MyApp
-0.03 xxx
+0.03 23 Aug 2008
* fix make_query() to return hash ref like
other Models do.
+ * updates for new core API in 0.29
+0.04 24 Aug 2008
+ * switch to DBIx::Class::RDBOHelpers for rel introspection.
+
+
+
+
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/MANIFEST
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/MANIFEST 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/MANIFEST 2008-08-24 06:50:58 UTC (rev 8267)
@@ -18,6 +18,7 @@
t/MyDB/Main/Artist.pm
t/MyDB/Main/Cd.pm
t/MyDB/Main/Track.pm
+t/MyDB/Main/CdTrackJoin.pm
t/example/MyApp/Changes
t/example/MyApp/lib/MyApp.pm
t/example/MyApp/lib/MyApp/Controller/Album.pm
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Makefile.PL
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Makefile.PL 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/Makefile.PL 2008-08-24 06:50:58 UTC (rev 8267)
@@ -11,10 +11,10 @@
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
- 'CatalystX::CRUD' => 0.28,
+ 'CatalystX::CRUD' => 0.29,
'DBIx::Class' => 0,
'Catalyst::Model::DBIC::Schema' => 0,
- 'DBIx::Class::IntrospectableM2M' => 0,
+ 'DBIx::Class::RDBOHelpers' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'CatalystX-CRUD-ModelAdapter-DBIC-*' },
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-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm 2008-08-24 06:50:58 UTC (rev 8267)
@@ -1,13 +1,16 @@
package CatalystX::CRUD::ModelAdapter::DBIC;
use warnings;
use strict;
-use base qw( CatalystX::CRUD::ModelAdapter CatalystX::CRUD::Model::Utils );
+use base qw(
+ CatalystX::CRUD::ModelAdapter
+ CatalystX::CRUD::Model::Utils
+);
use Class::C3;
use Scalar::Util qw( weaken );
use Carp;
use Data::Dump qw( dump );
-our $VERSION = '0.03';
+our $VERSION = '0.04';
=head1 NAME
@@ -129,6 +132,9 @@
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);
return $rs;
@@ -208,6 +214,8 @@
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);
}
@@ -232,15 +240,13 @@
my ( $self, $controller, $c, $obj, $rel, $for_val ) = @_;
my $rinfo = $self->_get_rel_meta( $controller, $c, $obj, $rel );
- #carp dump $rinfo;
- if ( !exists $rinfo->{class} ) {
+ #carp "add_related: " . dump $rinfo;
- # isa m2m
- # must find the foreign object to pass to add_to_$rel()
+ if ( exists $rinfo->{m2m} ) {
my $for_obj
- = $self->_get_m2m_foreign_object( $controller, $c, $obj, $rinfo,
- $for_val );
- my $add_method = $rinfo->{add_method};
+ = $self->_get_m2m_foreign_object( $controller, $c, $obj, $rel,
+ $rinfo, $for_val );
+ my $add_method = 'add_to_' . $rinfo->{m2m}->{method_name};
$obj->$add_method($for_obj);
}
else {
@@ -249,36 +255,21 @@
}
sub _get_m2m_foreign_object {
- my ( $self, $controller, $c, $obj, $rinfo, $for_val ) = @_;
- my $o2m_rel = $rinfo->{relation};
- my $o2m_rinfo = $self->_get_rel_meta( $controller, $c, $obj, $o2m_rel );
-
- #carp dump $o2m_rinfo;
-
- my $map_class = $o2m_rinfo->{class};
- my ( $for_class, $for_pk );
- for my $for_rel ( $map_class->relationships ) {
- my $for_rel_info = $map_class->relationship_info($for_rel);
-
- #carp "for_rel: " . dump $for_rel_info;
-
- # this is a FK in the map table but which one?
- # we want the other side
- if ( !$obj->isa( $for_rel_info->{class} ) ) {
- $for_class = $for_rel_info->{class};
- ($for_pk) = $for_class->primary_columns; # TODO multiple?
- }
-
+ my ( $self, $controller, $c, $obj, $rel, $rinfo, $for_val ) = @_;
+ if ( !exists $rinfo->{m2m} ) {
+ $self->throw_error("relationship $rel is not a many-to-many");
}
- #carp "for_class = $for_class";
- #carp "for_pk = $for_pk";
+ #carp "get foreign object for $rel : " . dump $rinfo;
+ my $m2m = $rinfo->{m2m};
+ my $foreign_class = $m2m->{foreign_class};
+ my $fpk = $m2m->{foreign_column};
my $for_obj
- = $c->model( $self->model_name )->resultset($for_class)
- ->find( { $for_pk => $for_val } )
+ = $c->model( $self->model_name )->resultset($foreign_class)
+ ->find( { $fpk => $for_val } )
or $self->throw_error(
- "can't find foreign object in $for_class for $for_val");
+ "can't find foreign object in $foreign_class for $for_val");
return $for_obj;
}
@@ -295,14 +286,14 @@
my $rinfo = $self->_get_rel_meta( $controller, $c, $obj, $rel );
#carp dump $rinfo;
- if ( !exists $rinfo->{class} ) {
+ if ( exists $rinfo->{m2m} ) {
# isa m2m
# must find the foreign object to pass to remove_from_$rel()
my $for_obj
- = $self->_get_m2m_foreign_object( $controller, $c, $obj, $rinfo,
- $for_val );
- my $rm_method = $rinfo->{remove_method};
+ = $self->_get_m2m_foreign_object( $controller, $c, $obj, $rel,
+ $rinfo, $for_val );
+ my $rm_method = 'remove_from_' . $rinfo->{m2m}->{method_name};
$obj->$rm_method($for_obj);
}
@@ -321,18 +312,20 @@
sub has_relationship {
my ( $self, $controller, $c, $obj, $rel ) = @_;
- if ( !$obj->can('_m2m_metadata') ) {
- $self->throw_error(
- "DBIx::Class::IntrospectableM2M not loaded for $obj");
+ eval { $obj->ensure_class_loaded('DBIx::Class::RDBOHelpers'); };
+ if ($@) {
+ $self->throw_error("DBIx::Class::RDBOHelpers not loaded for $obj");
}
- #carp dump $obj;
- #carp dump $obj->_m2m_metadata;
-
- return $obj->_m2m_metadata->{$rel} if exists $obj->_m2m_metadata->{$rel};
for ( $obj->relationships ) {
return $obj->relationship_info($_)
- if $_ eq $rel; # has_relationship() does not work??
+ if $_ eq $rel;
+
+ # m2m relationships are not keyed by their method name
+ my $info = $obj->relationship_info($_);
+ if ( exists $info->{m2m} and $info->{m2m}->{method_name} eq $rel ) {
+ return $info;
+ }
}
return;
}
@@ -350,26 +343,41 @@
my $self = shift;
my $controller = shift;
my $c = shift;
- return $self->{_field_names} if $self->{_field_names};
- my $obj = $c->model( $self->model_name )
- ->composed_schema->source( $self->_get_moniker( $controller, $c ) );
+ my $moniker = $self->_get_moniker( $controller, $c );
+ return $self->{_field_names}->{$moniker}
+ if exists $self->{_field_names}->{$moniker};
+
+ my $obj
+ = $c->model( $self->model_name )->composed_schema->class($moniker);
my @cols = $obj->columns;
my @rels = $obj->relationships;
my @fields;
for my $rel (@rels) {
- my $info = $obj->relationship_info($rel);
- my $rel_class = $info->{source};
- my @rel_cols = $rel_class->columns;
- push( @fields, map { $rel . '.' . $_ } @rel_cols );
+ my $info = $self->_get_rel_meta( $controller, $c, $obj, $rel );
+ my ( $rel_class, $prefix );
+
+ #warn "rel info for $moniker $rel: " . dump $info;
+ if ( exists $info->{m2m} ) {
+ $rel_class = $info->{m2m}->{foreign_class};
+ $prefix = $info->{m2m}->{map_to};
+ }
+ else {
+ $rel_class = $info->{class};
+ $prefix = $rel;
+ }
+ my @rel_cols = $rel_class->columns;
+ push( @fields, map { $prefix . '.' . $_ } @rel_cols );
}
for my $col (@cols) {
push( @fields, 'me.' . $col );
}
- $self->{_field_names} = \@fields;
+ #carp "field_names for $moniker : " . dump \@fields;
+ $self->{_field_names}->{$moniker} = \@fields;
+
return \@fields;
}
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-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/01-dbic.t 2008-08-24 06:50:58 UTC (rev 8267)
@@ -3,7 +3,7 @@
BEGIN {
use lib qw( ../../CatalystX-CRUD/trunk/lib t );
- $ENV{CATALYST_DEBUG} = $ENV{PERL_DEBUG} || 0;
+ $ENV{CATALYST_DEBUG} ||= 0;
use_ok('CatalystX::CRUD::ModelAdapter::DBIC');
@@ -31,15 +31,13 @@
"GET view" );
#diag( $res->content );
-is( $res->content, '{ cd => 3, title => "Beat It", trackid => 1 }',
- "GET track 1" );
+is( $res->content, '{ title => "Beat It", trackid => 1 }', "GET track 1" );
# create
ok( $res = request(
POST(
'/crud/0/save',
- [ cd => 3,
- title => 'Something New, Something Blue',
+ [ title => 'Something New, Something Blue',
trackid => 0
]
)
@@ -49,16 +47,13 @@
#diag( $res->content );
is( $res->content,
- '{ cd => 3, title => "Something New, Something Blue", trackid => 8 }',
+ '{ title => "Something New, Something Blue", trackid => 8 }',
"POST new track"
);
# test *_related features
-ok( $res = request(
- POST( '/crud/3/cds/1/add', [] ),
- "/crud/3/multitracks/1/add"
- )
+ok( $res = request( POST( '/crud/3/cds/1/add', [] ), "/crud/3/tracks/1/add" )
);
is( $res->headers->{status}, 204, "POST returned OK" );
@@ -67,7 +62,7 @@
ok( $res = request(
POST( '/crud/3/cds/1/remove', [] ),
- "/crud/3/multitracks/1/remove"
+ "/crud/3/tracks/1/remove"
)
);
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Artist.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Artist.pm 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Artist.pm 2008-08-24 06:50:58 UTC (rev 8267)
@@ -1,6 +1,6 @@
package MyDB::Main::Artist;
use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/IntrospectableM2M Core/);
+__PACKAGE__->load_components(qw/RDBOHelpers Core/);
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(qw/ artistid name /);
__PACKAGE__->set_primary_key('artistid');
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Cd.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Cd.pm 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Cd.pm 2008-08-24 06:50:58 UTC (rev 8267)
@@ -1,18 +1,17 @@
package MyDB::Main::Cd;
use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/IntrospectableM2M Core/);
+__PACKAGE__->load_components(qw/RDBOHelpers Core/);
__PACKAGE__->table('cd');
__PACKAGE__->add_columns(qw/ cdid artist title/);
__PACKAGE__->set_primary_key('cdid');
__PACKAGE__->belongs_to( 'artist' => 'MyDB::Main::Artist' );
-__PACKAGE__->has_many( 'tracks' => 'MyDB::Main::Track' );
__PACKAGE__->has_many(
'cd_tracks' => 'MyDB::Main::CdTrackJoin',
'cdid'
);
__PACKAGE__->many_to_many(
- 'multitracks' => 'cd_tracks',
- 'trackid'
+ 'tracks' => 'cd_tracks',
+ 'track'
);
1;
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/CdTrackJoin.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/CdTrackJoin.pm 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/CdTrackJoin.pm 2008-08-24 06:50:58 UTC (rev 8267)
@@ -1,10 +1,10 @@
package MyDB::Main::CdTrackJoin;
use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/ IntrospectableM2M Core /);
+__PACKAGE__->load_components(qw/ RDBOHelpers Core /);
__PACKAGE__->table('cd_track_join');
__PACKAGE__->add_columns(qw/ trackid cdid id /);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'cdid' => 'MyDB::Main::Cd' );
-__PACKAGE__->belongs_to( 'trackid' => 'MyDB::Main::Track' );
+__PACKAGE__->belongs_to( 'cd' => 'MyDB::Main::Cd', 'cdid' );
+__PACKAGE__->belongs_to( 'track' => 'MyDB::Main::Track', 'trackid' );
1;
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Track.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Track.pm 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/MyDB/Main/Track.pm 2008-08-24 06:50:58 UTC (rev 8267)
@@ -1,17 +1,16 @@
package MyDB::Main::Track;
use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/IntrospectableM2M Core/);
+__PACKAGE__->load_components(qw/RDBOHelpers Core/);
__PACKAGE__->table('track');
-__PACKAGE__->add_columns(qw/ trackid cd title/);
+__PACKAGE__->add_columns(qw/ trackid title /);
__PACKAGE__->set_primary_key('trackid');
-__PACKAGE__->belongs_to( 'cd' => 'MyDB::Main::Cd' );
__PACKAGE__->has_many(
- 'cd_tracks' => 'MyDB::Main::CdTrackJoin',
+ 'track_cds' => 'MyDB::Main::CdTrackJoin',
'trackid'
);
__PACKAGE__->many_to_many(
- 'cds' => 'cd_tracks',
- 'cdid'
+ 'cds' => 'track_cds',
+ 'cd'
);
1;
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/insertdb.pl
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/insertdb.pl 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/insertdb.pl 2008-08-24 06:50:58 UTC (rev 8267)
@@ -28,7 +28,6 @@
qq{
CREATE TABLE track (
trackid INTEGER PRIMARY KEY AUTOINCREMENT,
- cd INTEGER NOT NULL REFERENCES cd(cdid),
title TEXT NOT NULL
);
}
@@ -76,11 +75,16 @@
'The Way I Am' => 'The Marshall Mathers LP',
);
+$schema->populate( 'Track', [ ['title'], map { [$_] } sort keys %tracks ] );
+
my @tracks;
-foreach my $track ( sort keys %tracks ) {
- my $cdname
- = $schema->resultset('Cd')->search( { title => $tracks{$track}, } );
- push @tracks, [ $cdname->first, $track ];
+foreach my $track_title ( sort keys %tracks ) {
+ my $cdid = $schema->resultset('Cd')
+ ->search( { title => $tracks{$track_title}, } )->first->cdid;
+ my $trackid
+ = $schema->resultset('Track')->find( { title => $track_title } )
+ ->trackid;
+ push @tracks, [ $cdid, $trackid ];
}
-$schema->populate( 'Track', [ [qw/cd title/], @tracks, ] );
+$schema->populate( 'CdTrackJoin', [ [qw/cdid trackid/], @tracks, ] );
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp/Controller/CRUD.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp/Controller/CRUD.pm 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp/Controller/CRUD.pm 2008-08-24 06:50:58 UTC (rev 8267)
@@ -8,7 +8,7 @@
__PACKAGE__->config(
form_class => 'MyForm',
- form_fields => [qw( title cd trackid )],
+ form_fields => [qw( title trackid )],
init_form => 'init_with_track',
init_object => 'track_from_form',
default_template => 'no/such/file',
@@ -17,8 +17,8 @@
model_meta => {
dbic_schema => 'Track',
resultset_opts => {
- join => [qw/ cd /],
- prefetch => [qw/ cd /]
+ join => { track_cds => 'cd' },
+ prefetch => { track_cds => 'cd' }
}
},
primary_key => 'trackid',
@@ -50,7 +50,13 @@
my $rs = $self->do_model( $c, 'iterator' );
while ( my $track = $rs->next ) {
- #$self->serialize_object( $c, $track );
+
+ # $self->serialize_object( $c, $track );
+ # warn sprintf(
+ # "cd title = %s cd id = %d\n",
+ # $track->cds->first->title,
+ # $track->cds->first->cdid
+ # );
$count++;
}
@@ -64,6 +70,7 @@
my $count = 0;
my @results = $self->do_model( $c, 'search' );
for my $r (@results) {
+
#$self->serialize_object( $c, $r );
$count++;
}
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp.pm 2008-08-24 03:53:21 UTC (rev 8266)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/t/lib/MyApp.pm 2008-08-24 06:50:58 UTC (rev 8267)
@@ -32,12 +32,8 @@
my $schema = shift;
my $count = shift;
my $cdtitle = shift;
- my $rs = $schema->resultset('Track')->search(
- { 'cd.title' => $cdtitle },
- { join => [qw/ cd /],
- prefetch => [qw/ cd /]
- }
- );
+ my $rs
+ = $schema->resultset('Cd')->find( { 'title' => $cdtitle }, )->tracks;
while ( my $track = $rs->next ) {
$$count++;
}
@@ -48,12 +44,13 @@
my $schema = shift;
my $count = shift;
my $artistname = shift;
- my $rs = $schema->resultset('Track')->search(
- { 'artist.name' => $artistname },
- { join => { 'cd' => 'artist' }, }
- );
- while ( my $track = $rs->next ) {
- $$count++;
+ my $rs = $schema->resultset('Artist')->find( { 'name' => $artistname }, )
+ ->cds;
+ while ( my $cd = $rs->next ) {
+ my $tracks = $cd->tracks;
+ while ( my $track = $tracks->next ) {
+ $$count++;
+ }
}
}
@@ -63,10 +60,8 @@
my $count = shift;
my $tracktitle = shift;
- my $rs
- = $schema->resultset('Cd')->search( { 'tracks.title' => $tracktitle },
- { join => [qw/ tracks /], } );
- my $cd = $rs->first;
+ my $rs = $schema->resultset('Track')->find( { 'title' => $tracktitle } );
+ my $cd = $rs->cds->first;
$$count++;
}
@@ -92,11 +87,8 @@
my $count = shift;
my $tracktitle = shift;
- my $rs = $schema->resultset('Artist')->search(
- { 'tracks.title' => $tracktitle },
- { join => { 'cds' => 'tracks' } }
- );
- my $artist = $rs->first;
+ my $rs = $schema->resultset('Track')->find( { 'title' => $tracktitle } );
+ my $artist = $rs->cds->first->artist;
$$count++;
}
More information about the Catalyst-commits
mailing list