On Fri, Feb 22, 2013 at 4:58 PM, Peter Rabbitson <rabbit+d...@rabbit.us> wrote:
>
> The test is comprehensive enough, no further questions. It would be
> great if you could convert it to a DBIC-internal test, for example based
> off of:
> https://github.com/dbsrgits/dbix-class/blob/master/t/prefetch/via_search_related.t
> (otherwise one of us got to do it, tests added to the core suite need to
> follow the internal schema)



I've had a go, trying to preserve the intent of Colin's original test
- it still fails locally with the newer DBIC; I realise there's scope
for some improvement in the test, but I didn't want to start messing
about with it too much.

Hopefully it's easier for you to make any final tweaks:

---- cut here ----
use strict;
use warnings;

use Test::More;

use lib 't/lib';
use DBICTest;

my $schema = DBICTest->init_schema();

ok (my $artist = $schema->resultset('Artist')->create({artistid=>804,
name=>'thefoo'}), "Add an artist 'thefoo'");

my $cds = 
[{cdid=>101,title=>'foobar_1',year=>1974},{cdid=>102,title=>'foobar_2',year=>1974}];

foreach my $cd (@{$cds}){
    ok ($artist->create_related('cds', $cd), "Added a CD for artist 'thefoo'");
}

my $found_artist = $schema->resultset('Artist')->find(
    {'me.artistid' => 804},
    { prefetch    => 'cds' }
);

my $cd = $found_artist->cds->search({cdid => 102});
is ($cd->first->id, 102, "Expected CD with ID 102");

done_testing;
---- cut here ----





Chiz

--
Chisel
e: chi...@chizography.net
w: http://chizography.net

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to