From: Peter Rabbitson Date: Sat, 7 Sep 2013 16:05:38 +0000 (+0100) Subject: Augment test suite with oddball relationship declarations X-Git-Tag: v0.08260~148 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=98fcc1c08b73df1c66c41fb4cc736e824e9e4026 Augment test suite with oddball relationship declarations Among other things this tests for the issue described/solved in 9e7525a2 --- diff --git a/t/lib/DBICTest/Schema/Artist.pm b/t/lib/DBICTest/Schema/Artist.pm index 20affe0..34532dc 100644 --- a/t/lib/DBICTest/Schema/Artist.pm +++ b/t/lib/DBICTest/Schema/Artist.pm @@ -44,6 +44,8 @@ __PACKAGE__->mk_classdata('field_name_for', { name => 'artist name', }); +# the undef condition in this rel is *deliberate* +# tests oddball legacy syntax __PACKAGE__->has_many( cds => 'DBICTest::Schema::CD', undef, { order_by => { -asc => 'year'} }, diff --git a/t/lib/DBICTest/Schema/CD.pm b/t/lib/DBICTest/Schema/CD.pm index 77a1f19..45fdf6f 100644 --- a/t/lib/DBICTest/Schema/CD.pm +++ b/t/lib/DBICTest/Schema/CD.pm @@ -49,12 +49,15 @@ __PACKAGE__->belongs_to( very_long_artist_relationship => 'DBICTest::Schema::Art }); # in case this is a single-cd it promotes a track from another cd -__PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track', 'single_track', - { join_type => 'left'} +__PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track', + { 'foreign.trackid' => 'self.single_track' }, + { join_type => 'left'}, ); # add a non-left single relationship for the complex prefetch tests -__PACKAGE__->belongs_to( existing_single_track => 'DBICTest::Schema::Track', 'single_track'); +__PACKAGE__->belongs_to( existing_single_track => 'DBICTest::Schema::Track', + { 'foreign.trackid' => 'self.single_track' }, +); __PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track' ); __PACKAGE__->has_many( @@ -65,6 +68,8 @@ __PACKAGE__->has_many( cd_to_producer => 'DBICTest::Schema::CD_to_Producer' => 'cd' ); +# the undef condition in this rel is *deliberate* +# tests oddball legacy syntax __PACKAGE__->might_have( liner_notes => 'DBICTest::Schema::LinerNotes', undef, { proxy => [ qw/notes/ ] }, @@ -79,7 +84,7 @@ __PACKAGE__->many_to_many( ); __PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre', - { 'foreign.genreid' => 'self.genreid' }, + 'genreid', { join_type => 'left', on_delete => 'SET NULL', diff --git a/t/lib/DBICTest/Schema/CD_to_Producer.pm b/t/lib/DBICTest/Schema/CD_to_Producer.pm index b416797..b4b064a 100644 --- a/t/lib/DBICTest/Schema/CD_to_Producer.pm +++ b/t/lib/DBICTest/Schema/CD_to_Producer.pm @@ -14,9 +14,10 @@ __PACKAGE__->add_columns( ); __PACKAGE__->set_primary_key(qw/cd producer/); +# the undef condition in this rel is *deliberate* +# tests oddball legacy syntax __PACKAGE__->belongs_to( - 'cd', 'DBICTest::Schema::CD', - { 'foreign.cdid' => 'self.cd' } + 'cd', 'DBICTest::Schema::CD' ); __PACKAGE__->belongs_to( diff --git a/t/lib/DBICTest/Schema/ForceForeign.pm b/t/lib/DBICTest/Schema/ForceForeign.pm index a870f3e..2fb7078 100644 --- a/t/lib/DBICTest/Schema/ForceForeign.pm +++ b/t/lib/DBICTest/Schema/ForceForeign.pm @@ -15,8 +15,7 @@ __PACKAGE__->set_primary_key(qw/artist/); # Normally this would not appear as a FK constraint # since it uses the PK -__PACKAGE__->might_have('artist_1', 'DBICTest::Schema::Artist', - { 'foreign.artistid' => 'self.artist' }, +__PACKAGE__->might_have('artist_1', 'DBICTest::Schema::Artist', 'artistid', { is_foreign_key_constraint => 1 }, ); diff --git a/t/lib/DBICTest/Schema/Track.pm b/t/lib/DBICTest/Schema/Track.pm index b82545a..5077bd0 100644 --- a/t/lib/DBICTest/Schema/Track.pm +++ b/t/lib/DBICTest/Schema/Track.pm @@ -48,7 +48,8 @@ __PACKAGE__->add_unique_constraint([ qw/cd title/ ]); __PACKAGE__->position_column ('position'); __PACKAGE__->grouping_column ('cd'); - +# the undef condition in this rel is *deliberate* +# tests oddball legacy syntax __PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, { proxy => { cd_title => 'title' }, }); @@ -62,13 +63,13 @@ __PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' ); __PACKAGE__->belongs_to( "year1999cd", "DBICTest::Schema::Year1999CDs", - { "foreign.cdid" => "self.cd" }, + 'cd', { join_type => 'left' }, # the relationship is of course optional ); __PACKAGE__->belongs_to( "year2000cd", "DBICTest::Schema::Year2000CDs", - { "foreign.cdid" => "self.cd" }, + 'cd', { join_type => 'left' }, ); diff --git a/t/lib/DBICTest/Schema/Year1999CDs.pm b/t/lib/DBICTest/Schema/Year1999CDs.pm index e13f044..d3b6197 100644 --- a/t/lib/DBICTest/Schema/Year1999CDs.pm +++ b/t/lib/DBICTest/Schema/Year1999CDs.pm @@ -36,7 +36,6 @@ __PACKAGE__->set_primary_key('cdid'); __PACKAGE__->add_unique_constraint([ qw/artist title/ ]); __PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist' ); -__PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track', - { "foreign.cd" => "self.cdid" }); +__PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track', 'cd' ); 1; diff --git a/t/lib/DBICTest/Schema/Year2000CDs.pm b/t/lib/DBICTest/Schema/Year2000CDs.pm index f0890a3..3ae7de5 100644 --- a/t/lib/DBICTest/Schema/Year2000CDs.pm +++ b/t/lib/DBICTest/Schema/Year2000CDs.pm @@ -16,7 +16,6 @@ __PACKAGE__->result_source_instance->view_definition( sprintf ( )); __PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist' ); -__PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track', - { "foreign.cd" => "self.cdid" }); +__PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track', 'cd' ); 1;