9 my $schema = DBICTest->init_schema();
11 # For fully intuitive multicreate any relationships in a chain
12 # that do not exist for one reason or another should be created,
13 # even if the preceeding relationship already exists.
15 # To get this to work a minor rewrite of find() is necessary, and
16 # more importantly some sort of recursive_insert() call needs to
17 # be available. The way things will work then is:
18 # *) while traversing the hierarchy code calls find_or_create()
19 # *) this in turn calls find(%\nested_dataset)
20 # *) this should return not only the existing object, but must
21 # also attach all non-existing (in fact maybe existing) related
22 # bits of data to it, with in_storage => 0
23 # *) then before returning the result of the succesful find(), we
24 # simply call $obj->recursive_insert and all is dandy
26 # Since this will not be a very clean solution, todoifying for the
27 # time being until an actual need arises
31 my $TODO_msg = "See comment at top of @{[ __FILE__ ]} for discussion of the TODO";
35 $counts->{$_} = $schema->resultset($_)->count for qw/Track CD Genre/;
37 my $existing_nogen_cd = $schema->resultset('CD')->search (
38 { 'genre.genreid' => undef },
42 $schema->resultset('Track')->create ({
43 title => 'Sugar-coated',
45 title => $existing_nogen_cd->title,
47 name => 'sugar genre',
52 is ($schema->resultset('Track')->count, $counts->{Track} + 1, '1 new track');
53 is ($schema->resultset('CD')->count, $counts->{CD}, 'No new cds');
56 todo_skip $TODO_msg, 1;
57 is ($schema->resultset('Genre')->count, $counts->{Genre} + 1, '1 new genre');
58 is ($existing_nogen_cd->genre->title, 'sugar genre', 'Correct genre assigned to CD');
64 $counts->{$_} = $schema->resultset($_)->count for qw/Artist CD Producer/;
67 my $artist = $schema->resultset('Artist')->first;
68 my $producer = $schema->resultset('Producer')->create ({ name => 'the queen of england' });
70 $schema->resultset('CD')->create ({
77 name => $producer->name,
92 is ($schema->resultset('Artist')->count, $counts->{Artist}, 'No new artists');
93 is ($schema->resultset('Producer')->count, $counts->{Producer} + 1, '1 new producers');
95 local $TODO = $TODO_msg;
96 is ($schema->resultset('CD')->count, $counts->{CD} + 2, '2 new cds');
98 is ($producer->cds->count, 2, 'CDs assigned to correct producer');
100 [ $producer->cds->search ({}, { order_by => 'title' })->get_column('title')->all],
101 [ qw/queen1 queen2/ ],
104 }, 'create() did not throw');