X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcdbi-t%2F09-has_many.t;h=28fa55efd9570a4471f089815eab4eb31d52fee1;hb=503363253e1fa2c35e3b5368dd7f453b9cfbc6a1;hp=2ff2633e5dff7dac305a25f59242fd209d25870d;hpb=b8e1e21f0fcd55e6e3ce987e57601b279a75b666;p=dbsrgits%2FDBIx-Class.git diff --git a/t/cdbi-t/09-has_many.t b/t/cdbi-t/09-has_many.t index 2ff2633..28fa55e 100644 --- a/t/cdbi-t/09-has_many.t +++ b/t/cdbi-t/09-has_many.t @@ -1,17 +1,20 @@ use strict; use Test::More; + BEGIN { - eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 30); + eval "use DBIx::Class::CDBICompat;"; + plan skip_all => 'Class::Trigger and DBIx::ContextualFetch required' if $@; + eval "use DBD::SQLite"; + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 31); } use lib 't/testlib'; use Film; use Actor; -Film->has_many(actors => Actor => 'Film', { order_by => 'name' }); Actor->has_a(Film => 'Film'); +Film->has_many(actors => 'Actor', { order_by => 'name' }); is(Actor->primary_column, 'id', "Actor primary OK"); ok(Actor->can('Salary'), "Actor table set-up OK"); @@ -107,3 +110,18 @@ ok $@, $@; is($as->Name, 'Arnold Schwarzenegger', "Arnie's still Arnie"); + +# Test infering of the foreign key of a has_many from an existing has_a +{ + use Thing; + use OtherThing; + + Thing->has_a(that_thing => "OtherThing"); + OtherThing->has_many(things => "Thing"); + + my $other_thing = OtherThing->create({ id => 1 }); + Thing->create({ id => 1, that_thing => $other_thing }); + Thing->create({ id => 2, that_thing => $other_thing }); + + is_deeply [sort map { $_->id } $other_thing->things], [1,2]; +}