X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frelationship%2Fcustom.t;h=a623b4b8f50c9394e337ed306c4799d0c74fd0fa;hb=8c7c83982c9ec8ebf8674c1100f9103f2af06402;hp=0cf32b56801138d348d7c31643d7c4944a34a603;hpb=1adbd3fc463c963d77fa2755eccaf6112e63487a;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/relationship/custom.t b/t/relationship/custom.t index 0cf32b5..a623b4b 100644 --- a/t/relationship/custom.t +++ b/t/relationship/custom.t @@ -151,6 +151,10 @@ is_deeply( } 'prefetchy-fetchy-fetch'; +# create_related a plain cd via the equoivalent coderef cond, with no extra conditions +lives_ok { + $artist->create_related('cds_cref_cond', { title => 'related creation via coderef cond', year => '2010' } ); +} 'created_related with simple condition works'; # try to create_related a 80s cd throws_ok { @@ -159,7 +163,8 @@ throws_ok { 'Create failed - complex cond'; # now supply an explicit arg overwriting the ambiguous cond -my $id_2020 = $artist->create_related('cds_80s', { title => 'related creation 2', year => '2020' })->id; +my $cd_2020 = $artist->create_related('cds_80s', { title => 'related creation 2', year => '2020' }); +my $id_2020 = $cd_2020->id; is( $schema->resultset('CD')->find($id_2020)->title, 'related creation 2', @@ -268,4 +273,21 @@ is_deeply ( 'Prefetched singles in proper order' ); +# test set_from_related with a belongs_to custom condition +my $cd = $schema->resultset("CD")->find(4); +$artist = $cd->search_related('artist'); +my $track = $schema->resultset("Track")->create( { + trackid => 1, + cd => 3, + position => 99, + title => 'Some Track' +} ); +$track->set_from_related( cd_cref_cond => $cd ); +is ($track->get_column('cd'), 4, 'set from related via coderef cond'); +is_deeply ( + { $track->cd->get_columns }, + { $cd->get_columns }, + 'set from related via coderef cond inflates properly', +); + done_testing;