Augment test suite with oddball relationship declarations
Peter Rabbitson [Sat, 7 Sep 2013 16:05:38 +0000 (17:05 +0100)]
Among other things this tests for the issue described/solved in 9e7525a2

t/lib/DBICTest/Schema/Artist.pm
t/lib/DBICTest/Schema/CD.pm
t/lib/DBICTest/Schema/CD_to_Producer.pm
t/lib/DBICTest/Schema/ForceForeign.pm
t/lib/DBICTest/Schema/Track.pm
t/lib/DBICTest/Schema/Year1999CDs.pm
t/lib/DBICTest/Schema/Year2000CDs.pm

index 20affe0..34532dc 100644 (file)
@@ -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'} },
index 77a1f19..45fdf6f 100644 (file)
@@ -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',
index b416797..b4b064a 100644 (file)
@@ -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(
index a870f3e..2fb7078 100644 (file)
@@ -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 },
 );
 
index b82545a..5077bd0 100644 (file)
@@ -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' },
 );
 
index e13f044..d3b6197 100644 (file)
@@ -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;
index f0890a3..3ae7de5 100644 (file)
@@ -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;