Merge 'trunk' into 'multi_stuff'
Rob Kinyon [Thu, 19 Feb 2009 03:04:53 +0000 (03:04 +0000)]
r5338@rkinyon-lt-osx (orig r5337):  castaway | 2009-01-21 17:55:19 -0500
Docs fixed, tests not fail..

r5339@rkinyon-lt-osx (orig r5338):  ribasushi | 2009-01-23 02:37:10 -0500
Dev-Release 0.08099_06
r5340@rkinyon-lt-osx (orig r5339):  ribasushi | 2009-01-23 06:14:29 -0500
Some doc fixes by dandv
r5341@rkinyon-lt-osx (orig r5340):  ribasushi | 2009-01-23 07:45:43 -0500
more typo patches by dandv
r5346@rkinyon-lt-osx (orig r5345):  ribasushi | 2009-01-24 15:20:58 -0500
Add feature-list from nixed 09 branch
r5348@rkinyon-lt-osx (orig r5347):  ribasushi | 2009-01-25 04:54:03 -0500
Adjust MANIFEST
r5349@rkinyon-lt-osx (orig r5348):  ribasushi | 2009-01-25 05:09:41 -0500
First stab at restructuring with tests_recursive() - no functional changes
r5350@rkinyon-lt-osx (orig r5349):  ribasushi | 2009-01-25 05:46:50 -0500
ignore MANIFEST
r5352@rkinyon-lt-osx (orig r5351):  ribasushi | 2009-01-27 04:14:29 -0500
Test all available JSON:: implementations in 89dbicadmin.t
r5355@rkinyon-lt-osx (orig r5354):  ribasushi | 2009-01-28 02:45:46 -0500
Special treatment of windows users - you can not segfault in a fork as there is no proper fork()
r5356@rkinyon-lt-osx (orig r5355):  ribasushi | 2009-01-28 04:45:25 -0500
make load_optional_class smarter when confronted with a PAR environment
r5357@rkinyon-lt-osx (orig r5356):  ribasushi | 2009-01-28 05:07:01 -0500
Older versions behave erratically in the new reentrant test
r5358@rkinyon-lt-osx (orig r5357):  ribasushi | 2009-01-28 05:08:03 -0500
wording
r5359@rkinyon-lt-osx (orig r5358):  dhoss | 2009-01-28 06:06:08 -0500
Fixed spelling error

r5360@rkinyon-lt-osx (orig r5359):  dhoss | 2009-01-28 06:11:45 -0500
testing dhoss's permissions

r5361@rkinyon-lt-osx (orig r5360):  dhoss | 2009-01-28 06:13:25 -0500
removed test variable

r5365@rkinyon-lt-osx (orig r5364):  ribasushi | 2009-01-29 03:44:25 -0500
Backporting uncovered an incomplete test
r5369@rkinyon-lt-osx (orig r5368):  ribasushi | 2009-01-29 04:14:31 -0500
Sanify 746mssql.t
r5371@rkinyon-lt-osx (orig r5370):  ribasushi | 2009-01-29 04:41:53 -0500
A pass is not strictly necessary for a test connection
r5372@rkinyon-lt-osx (orig r5371):  ribasushi | 2009-01-29 09:29:22 -0500
More verbosity as tomboh suggested
r5374@rkinyon-lt-osx (orig r5373):  ribasushi | 2009-01-29 13:45:46 -0500
Add the sqla test harness to the stopgap branch
r5380@rkinyon-lt-osx (orig r5379):  jmmills | 2009-01-29 20:37:01 -0500
Added a more verbose non column accessor example.

r5381@rkinyon-lt-osx (orig r5380):  jmmills | 2009-01-29 20:42:02 -0500
editorial typo in my previous commit.

r5383@rkinyon-lt-osx (orig r5382):  semifor | 2009-01-30 08:54:42 -0500
Bring test current with DBICTest schema.
r5384@rkinyon-lt-osx (orig r5383):  castaway | 2009-01-30 09:27:38 -0500
DB2 compatibility fix, update test to add new artist column (ick)
remove code that calls now removed sub _RowNumberOver

r5385@rkinyon-lt-osx (orig r5384):  ribasushi | 2009-01-30 09:32:42 -0500
Add the _find_syntax caching back
r5386@rkinyon-lt-osx (orig r5385):  castaway | 2009-01-30 09:33:24 -0500
DB2 compat: add new artist rank field to col_info_for test

r5393@rkinyon-lt-osx (orig r5392):  ribasushi | 2009-01-31 15:40:50 -0500
pod align by dandv
r5394@rkinyon-lt-osx (orig r5393):  ribasushi | 2009-02-01 16:33:32 -0500
Fix the dbicadmin test for good
r5395@rkinyon-lt-osx (orig r5394):  ribasushi | 2009-02-01 17:44:39 -0500
Fix the dbicadmin test for good (take 2)
r5400@rkinyon-lt-osx (orig r5399):  ribasushi | 2009-02-02 12:38:16 -0500
Bring back _RowNumberOver deleted in the sqla commotion (revs: 5096,5322,5383)
r5401@rkinyon-lt-osx (orig r5400):  ribasushi | 2009-02-02 12:52:20 -0500
part 2
r5414@rkinyon-lt-osx (orig r5413):  ribasushi | 2009-02-05 04:09:39 -0500
Commit some debugging code
r5420@rkinyon-lt-osx (orig r5419):  plu | 2009-02-07 08:40:41 -0500
Possible to set locale in IC::DateTime extra => {} config
r5427@rkinyon-lt-osx (orig r5426):  ribasushi | 2009-02-07 12:57:53 -0500
Up trunk dependency versions
r5428@rkinyon-lt-osx (orig r5427):  ribasushi | 2009-02-07 12:59:04 -0500
Up dependency on SQLT (releasing now)
r5432@rkinyon-lt-osx (orig r5431):  groditi | 2009-02-09 15:27:27 -0500
backporting the set_column/store_column fix
r5433@rkinyon-lt-osx (orig r5432):  groditi | 2009-02-09 15:29:03 -0500
ahhhh my bad. svk patch ne patch. oops adding missing file
r5439@rkinyon-lt-osx (orig r5438):  ribasushi | 2009-02-10 05:18:09 -0500
Finally make the indexer happy wrt SQL::Translator::Parser::DBIx::Class
Hide DBIx::Class::CDBICompat::ColumnGroups::GrouperShim (was never indexed to begin with)

r5441@rkinyon-lt-osx (orig r5440):  ribasushi | 2009-02-10 06:19:20 -0500
More rh-bug related stuff:
- Improve message emmitted when confronted with a buggy system
- Port forgotten pieces from trunk to stopgap
r5442@rkinyon-lt-osx (orig r5441):  castaway | 2009-02-10 08:57:34 -0500
More docs, pointing at using deploy/create_ddl_dir

r5445@rkinyon-lt-osx (orig r5444):  castaway | 2009-02-10 16:41:58 -0500
1) Add docs to ATTRIBUTES to better explain where to use them
2) Make all() die if passed arguments.

r5447@rkinyon-lt-osx (orig r5446):  ribasushi | 2009-02-11 03:24:58 -0500
Test for resultset corruption by search()
r5448@rkinyon-lt-osx (orig r5447):  ribasushi | 2009-02-11 04:02:42 -0500
Add a weird extra test, that should work nevertheless
r5449@rkinyon-lt-osx (orig r5448):  ribasushi | 2009-02-11 04:17:55 -0500
Add missing shallow copy of seen_join
r5450@rkinyon-lt-osx (orig r5449):  ribasushi | 2009-02-11 05:37:36 -0500
make single() die if passed attributes
r5455@rkinyon-lt-osx (orig r5454):  nigel | 2009-02-11 10:07:28 -0500
 r10743@hex:  nigel | 2009-02-11 15:07:05 +0000
 Documentation update on startup speed

r5459@rkinyon-lt-osx (orig r5458):  groditi | 2009-02-11 20:49:26 -0500
fixed bug for undef_on_null_fk edge case
r5464@rkinyon-lt-osx (orig r5463):  nigel | 2009-02-12 09:27:38 -0500
 r10772@hex:  nigel | 2009-02-12 14:27:22 +0000
 Made update() on a rs that includes joins complain in the same way that delete() does.  Added tests for both update and delete checks.

r5465@rkinyon-lt-osx (orig r5464):  plu | 2009-02-13 05:27:36 -0500
Refactored and re-added r5041: Split sql statements for deploy only if SQLT::Producer returned a scalar containing all statements to be executed
r5466@rkinyon-lt-osx (orig r5465):  caelum | 2009-02-13 05:40:55 -0500
Some fixes for Oracle edge cases

r5467@rkinyon-lt-osx (orig r5466):  ribasushi | 2009-02-13 05:45:46 -0500
Some forgotten tests
r5468@rkinyon-lt-osx (orig r5467):  caelum | 2009-02-13 06:29:37 -0500
Throw exception on invalidated session if in a transaction.

r5472@rkinyon-lt-osx (orig r5471):  ribasushi | 2009-02-14 19:44:02 -0500
Make 81transactions.t DBIC_TRACE friendly
r5473@rkinyon-lt-osx (orig r5472):  ribasushi | 2009-02-14 19:45:44 -0500
A dbh_do statement executed with bind values will confuse the hell out of DBIC running in DBIC_TRACE=1 mode - stop sending TMI to _query_[start|end] from within dbh_do/_do_query
r5475@rkinyon-lt-osx (orig r5474):  plu | 2009-02-15 09:20:25 -0500
RT#38251: DBIx::Class::Storage::DBI::Oracle::Generic does not handle fully-qualified table names
r5480@rkinyon-lt-osx (orig r5479):  caelum | 2009-02-15 18:30:00 -0500
Improved connected logic for Oracle storage

r5481@rkinyon-lt-osx (orig r5480):  caelum | 2009-02-15 19:20:27 -0500
sorry, I fucked up the indentation...
r5482@rkinyon-lt-osx (orig r5481):  ribasushi | 2009-02-16 03:48:49 -0500
Some cleanups of oracle patch
r5490@rkinyon-lt-osx (orig r5489):  robkinyon | 2009-02-16 16:27:49 -0500
Added a bit of explanation to resultsets to cut down on the repeated questions in #dbix-class
r5492@rkinyon-lt-osx (orig r5491):  robkinyon | 2009-02-16 17:09:12 -0500
 r5378@rkinyon-lt-osx (orig r5377):  robkinyon | 2009-01-29 15:58:53 -0500
 Branch for subquery support
 r5443@rkinyon-lt-osx (orig r5442):  robkinyon | 2009-02-10 15:10:10 -0500
 Added as_query to ResultSet with a couple tests
 r5444@rkinyon-lt-osx (orig r5443):  robkinyon | 2009-02-10 15:23:27 -0500
 Added as_query() support to ResultSetColumn
 r5446@rkinyon-lt-osx (orig r5445):  robkinyon | 2009-02-10 17:53:48 -0500
 Switched to use is_same_sql_bind() per ribasushi's suggestion
 r5453@rkinyon-lt-osx (orig r5452):  robkinyon | 2009-02-11 09:45:23 -0500
 check in bombing test for subquery-with-as_query
 r5458@rkinyon-lt-osx (orig r5457):  robkinyon | 2009-02-11 11:24:11 -0500
 Checking in failing test
 r5470@rkinyon-lt-osx (orig r5469):  robkinyon | 2009-02-13 14:43:12 -0500
 Added as_sql and as_subselect as wrappers around as_query
 r5471@rkinyon-lt-osx (orig r5470):  robkinyon | 2009-02-13 14:56:40 -0500
 Added a passing test for initial simple subqueries
 r5479@rkinyon-lt-osx (orig r5478):  robkinyon | 2009-02-15 11:23:46 -0500
 Subqueries are done

r5500@rkinyon-lt-osx (orig r5499):  norbi | 2009-02-17 15:09:40 -0500
 r5616@vger:  mendel | 2009-02-17 20:39:09 +0100
  * Fixed to make it work with [colname => value] bind value format of SQLA.

r5501@rkinyon-lt-osx (orig r5500):  norbi | 2009-02-17 15:09:47 -0500
 r5621@vger:  mendel | 2009-02-17 21:09:08 +0100
  * Updated POD for using PostgreSQL arrays because of the \[$sql, @bind] bind value format change of SQLA.

r5502@rkinyon-lt-osx (orig r5501):  norbi | 2009-02-17 15:44:19 -0500
 r5624@vger:  mendel | 2009-02-17 21:11:58 +0100
  * Fixed the initial DROP TABLE statement (used to drop the wrong table).

r5503@rkinyon-lt-osx (orig r5502):  norbi | 2009-02-17 15:44:26 -0500
 r5625@vger:  mendel | 2009-02-17 21:43:54 +0100
  * Fixed the bug with omitting 'FOR UPDATE'/'FOR SHARED' (introduced from the 'subquery' branch, made 72pg.t fail).

r5504@rkinyon-lt-osx (orig r5503):  norbi | 2009-02-17 15:56:09 -0500
 r5628@vger:  mendel | 2009-02-17 21:55:54 +0100
  * Added the missing POD of a sub.

r5505@rkinyon-lt-osx (orig r5504):  norbi | 2009-02-17 16:08:05 -0500
 r5630@vger:  mendel | 2009-02-17 22:07:56 +0100
  * Fixed the bug in the test that made it fail in the END block even if all tests were SKIPped.

r5506@rkinyon-lt-osx (orig r5505):  castaway | 2009-02-17 16:22:05 -0500
Add multiple database/schema FAQs

r5507@rkinyon-lt-osx (orig r5506):  norbi | 2009-02-17 16:22:57 -0500
 r5632@vger:  mendel | 2009-02-17 22:22:50 +0100
  * Added new test subs (is_same_sql, is_same_bind) and new predicate sub (eq_sql_bind) to DBIC::SqlMakerTest (SQL::Abstract::Test has these, so made them available here, too).

r5508@rkinyon-lt-osx (orig r5507):  caelum | 2009-02-17 16:58:34 -0500
minor Oracle changes
r5509@rkinyon-lt-osx (orig r5508):  caelum | 2009-02-17 17:39:59 -0500
changed WriteAll; to WriteAll(); in Makefile.PL because of some sort of installation weirdness in some places
r5510@rkinyon-lt-osx (orig r5509):  caelum | 2009-02-17 17:52:28 -0500
changed DBD::SQLite from a test_requires to a configure_requires
r5511@rkinyon-lt-osx (orig r5510):  norbi | 2009-02-17 18:09:49 -0500
 r5635@vger:  mendel | 2009-02-18 00:09:36 +0100
  * Added new TODO tests for bind attributes (for ->select, ->update, ->delete).

r5522@rkinyon-lt-osx (orig r5521):  jnapiorkowski | 2009-02-18 14:35:19 -0500
I guess ensure_connected does not have a return value... so I cannot use it. Fix for replication issue where replicants always get marked as unavailable even when there is no problem with them
r5526@rkinyon-lt-osx (orig r5525):  robkinyon | 2009-02-18 14:59:26 -0500
 r5515@rkinyon-lt-osx (orig r5514):  robkinyon | 2009-02-17 21:37:09 -0500
 Moved the actual subquery test to a new subquery testfile
 r5516@rkinyon-lt-osx (orig r5515):  robkinyon | 2009-02-17 21:50:16 -0500
 Added TODO tests for +select and from with as_query
 r5517@rkinyon-lt-osx (orig r5516):  robkinyon | 2009-02-17 22:06:02 -0500
 The tests are truly failing tests
 r5518@rkinyon-lt-osx (orig r5517):  robkinyon | 2009-02-18 11:52:42 -0500
 as_query now provides its own parens
 r5519@rkinyon-lt-osx (orig r5518):  robkinyon | 2009-02-18 14:10:51 -0500
 Alias properly checks ->{attrs}{alias}
 r5520@rkinyon-lt-osx (orig r5519):  robkinyon | 2009-02-18 14:13:27 -0500
 Fixed a test expectation so the right failure is reported
 r5521@rkinyon-lt-osx (orig r5520):  robkinyon | 2009-02-18 14:19:28 -0500
 Marked tests as TODO for later
 r5523@rkinyon-lt-osx (orig r5522):  robkinyon | 2009-02-18 14:54:31 -0500
 Added my name
 r5524@rkinyon-lt-osx (orig r5523):  robkinyon | 2009-02-18 14:58:21 -0500
 Added some more POD in the Cookbook for correlated subqueries

r5527@rkinyon-lt-osx (orig r5526):  castaway | 2009-02-18 16:52:02 -0500
Improved docs/description lots

t/66relationship.t
t/96multi_create.t
t/96multi_create/cd_single.t [new file with mode: 0644]
t/96multi_create_new.t [new file with mode: 0644]
t/96multi_create_torture.t [new file with mode: 0644]
t/lib/DBICTest/Schema.pm
t/lib/DBICTest/Schema/Artist.pm
t/lib/DBICTest/Schema/Artwork.pm
t/lib/DBICTest/Schema/Artwork_to_Artist.pm [new file with mode: 0644]
t/lib/sqlite.sql

index 7f05be4..88f5c16 100644 (file)
@@ -268,33 +268,6 @@ $artist->cds->update({artist => $nartist->id});
 cmp_ok($artist->cds->count, '==', 0, "Correct new #cds for artist");
 cmp_ok($nartist->cds->count, '==', 2, "Correct new #cds for artist");
 
-my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode' });
-my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave in Silence', 'year' => 1982});
-eval {
-       $new_artist->insert;
-       $new_related_cd->insert;
-};
-is ($@, '', 'Staged insertion successful');
-ok($new_artist->in_storage, 'artist inserted');
-ok($new_related_cd->in_storage, 'new_related_cd inserted');
-
-TODO: {
-local $TODO = "TODOify for multicreate branch";
-my $new_cd = $schema->resultset("CD")->new_result({});
-my $new_related_artist = $new_cd->new_related('artist', { 'name' => 'Marillion',});
-lives_ok (
-    sub {
-       $new_related_artist->insert;
-       $new_cd->title( 'Misplaced Childhood' );
-       $new_cd->year ( 1985 );
-#       $new_cd->artist( $new_related_artist );  # For exact backward compatibility     # not sure what this means
-       $new_cd->insert;
-    },
-    'Reversed staged insertion successful'
-);
-ok($new_related_artist->in_storage, 'related artist inserted');
-ok($new_cd->in_storage, 'cd inserted');
-
 # check if is_foreign_key_constraint attr is set
 my $rs_normal = $schema->source('Track');
 my $relinfo = $rs_normal->relationship_info ('cd');
@@ -303,4 +276,3 @@ cmp_ok($relinfo->{attrs}{is_foreign_key_constraint}, '==', 1, "is_foreign_key_co
 my $rs_overridden = $schema->source('ForceForeign');
 my $relinfo_with_attr = $rs_overridden->relationship_info ('cd_3');
 cmp_ok($relinfo_with_attr->{attrs}{is_foreign_key_constraint}, '==', 0, "is_foreign_key_constraint defined for belongs_to relationships with attr.");
-}
index 4445f3f..9c75cac 100644 (file)
@@ -6,11 +6,11 @@ use Test::Exception;
 use lib qw(t/lib);
 use DBICTest;
 
-plan tests => 89;
+plan tests => 85;
 
 my $schema = DBICTest->init_schema();
 
-# simple create + parent (the stuff $rs belongs_to)
+diag '* simple create + parent (the stuff $rs belongs_to)';
 eval {
   my $cd = $schema->resultset('CD')->create({
     artist => { 
@@ -26,8 +26,7 @@ eval {
 };
 diag $@ if $@;
 
-# same as above but the child and parent have no values,
-# except for an explicit parent pk
+diag '* same as above but the child and parent have no values, except for an explicit parent pk';
 eval {
   my $bm_rs = $schema->resultset('Bookmark');
   my $bookmark = $bm_rs->create({
@@ -49,7 +48,7 @@ eval {
 };
 diag $@ if $@;
 
-# create over > 1 levels of has_many create (A => { has_many => { B => has_many => C } } )
+diag '* create over > 1 levels of has_many create (A => { has_many => { B => has_many => C } } )';
 eval {
   my $artist = $schema->resultset('Artist')->first;
   my $cd = $artist->create_related (cds => {
@@ -83,7 +82,7 @@ throws_ok (
   'create via update of multi relationships throws an exception'
 );
 
-# Create m2m while originating in the linker table
+diag '* Create m2m while originating in the linker table';
 eval {
   my $artist = $schema->resultset('Artist')->first;
   my $c2p = $schema->resultset('CD_to_Producer')->create ({
@@ -113,7 +112,19 @@ eval {
 };
 diag $@ if $@;
 
-# create over > 1 levels of might_have (A => { might_have => { B => has_many => C } } )
+diag (<<'DG');
+* Create over > 1 levels of might_have with multiple has_many and multiple m2m
+but starting at a has_many level
+
+CD -> has_many -> Tracks -> might have -> Single -> has_many -> Tracks
+                                               \
+                                                \-> has_many \
+                                                              --> CD2Producer
+                                                /-> has_many /
+                                               /
+                                          Producer
+DG
+
 eval {
   my $artist = $schema->resultset('Artist')->first;
   my $cd = $schema->resultset('CD')->create ({
@@ -122,7 +133,7 @@ eval {
     year => 2008,
     tracks => [
       {
-        position => 1,
+        position => 1, # some day me might test this with Ordered
         title => 'Off by one again',
       },
       {
@@ -141,7 +152,12 @@ eval {
               producer => {
                 name => 'K&R',
               }
-            }
+            },
+            {
+              producer => {
+                name => 'Don Knuth',
+              }
+            },
           ]
         },
       },
@@ -163,14 +179,82 @@ eval {
   is ($single->tracks->find ({ position => 1})->title, 'The dereferencer', 'Correct 1st track title');
   is ($single->tracks->find ({ position => 2})->title, 'The dereferencer II', 'Correct 2nd track title');
 
-  is ($single->cd_to_producer->count, 1, 'One producer created with the single cd');
-  is ($single->cd_to_producer->first->producer->name, 'K&R', 'Producer name correct');
+  is ($single->cd_to_producer->count, 2, 'Two producers created for the single cd');
+  is_deeply (
+    [ sort map { $_->producer->name } ($single->cd_to_producer->all) ],
+    ['Don Knuth', 'K&R'],
+    'Producers named correctly',
+  );
 };
 diag $@ if $@;
 
-TODO: {
-local $TODO = "Todoify for multicreate branch";
-# test might_have again but with a PK == FK in the middle (obviously not specified)
+diag (<<'DG');
+* Same as above but starting at the might_have directly
+
+Track -> might have -> Single -> has_many -> Tracks
+                           \
+                            \-> has_many \
+                                          --> CD2Producer
+                            /-> has_many /
+                           /
+                       Producer
+DG
+
+eval {
+  my $cd = $schema->resultset('CD')->first;
+  my $track = $schema->resultset('Track')->create ({
+    cd => $cd,
+    position => 77,  # some day me might test this with Ordered
+    title => 'Multicreate rocks',
+    cd_single => {
+      artist => $cd->artist,
+      year => 2008,
+      title => 'Disemboweling MultiCreate',
+      tracks => [
+        { title => 'Why does mst write this way', position => 1 },
+        { title => 'Chainsaw celebration', position => 2 },
+        { title => 'Purl cleans up', position => 3 },
+      ],
+      cd_to_producer => [
+        {
+          producer => {
+            name => 'mst',
+          }
+        },
+        {
+          producer => {
+            name => 'castaway',
+          }
+        },
+        {
+          producer => {
+            name => 'theorbtwo',
+          }
+        },
+      ]
+    },
+  });
+
+  isa_ok ($track, 'DBICTest::Track', 'Main Track object created');
+  is ($track->title, 'Multicreate rocks', 'Correct Track title');
+
+  my $single = $track->cd_single;
+  isa_ok ($single, 'DBICTest::CD', 'Created a single with the track');
+  is ($single->tracks->count, 3, '3 tracks on single CD');
+  is ($single->tracks->find ({ position => 1})->title, 'Why does mst write this way', 'Correct 1st track title');
+  is ($single->tracks->find ({ position => 2})->title, 'Chainsaw celebration', 'Correct 2nd track title');
+  is ($single->tracks->find ({ position => 3})->title, 'Purl cleans up', 'Correct 3rd track title');
+
+  is ($single->cd_to_producer->count, 3, '3 producers created for the single cd');
+  is_deeply (
+    [ sort map { $_->producer->name } ($single->cd_to_producer->all) ],
+    ['castaway', 'mst', 'theorbtwo'],
+    'Producers named correctly',
+  );
+};
+diag $@ if $@;
+
+diag '* Test might_have again but with a PK == FK in the middle (obviously not specified)';
 eval {
   my $artist = $schema->resultset('Artist')->first;
   my $cd = $schema->resultset('CD')->create ({
@@ -199,7 +283,6 @@ eval {
     'Images named correctly in objects',
   );
 
-
   my $artwork = $schema->resultset('Artwork')->search (
     { 'cd.title' => 'Music to code by at twilight' },
     { join => 'cd' },
@@ -215,7 +298,7 @@ eval {
 };
 diag $@ if $@;
 
-# test might_have again but with just a PK and FK (neither specified) in the mid-table
+diag '* Test might_have again but with just a PK and FK (neither specified) in the mid-table';
 eval {
   my $cd = $schema->resultset('CD')->first;
   my $track = $schema->resultset ('Track')->create ({
@@ -260,9 +343,59 @@ eval {
   );
 };
 diag $@ if $@;
-}
 
-# nested find_or_create
+diag (<<'DG');
+* Test a multilevel might-have with a PK == FK in the might_have/has_many table
+
+CD -> might have -> Artwork
+                       \
+                        \-> has_many \
+                                      --> Artwork_to_Artist
+                        /-> has_many /
+                       /
+                     Artist
+DG
+
+eval {
+  my $someartist = $schema->resultset('Artist')->first;
+  my $cd = $schema->resultset('CD')->create ({
+    artist => $someartist,
+    title => 'Music to code by until the cows come home',
+    year => 2008,
+    artwork => {
+      artwork_to_artist => [
+        { artist => { name => 'cowboy joe' } },
+        { artist => { name => 'billy the kid' } },
+      ],
+    },
+  });
+
+  isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
+  is ($cd->title, 'Music to code by until the cows come home', 'Correct CD title');
+
+  my $art_obj = $cd->artwork;
+  ok ($art_obj->has_column_loaded ('cd_id'), 'PK/FK present on artwork object');
+  is ($art_obj->artists->count, 2, 'Correct artwork creator count via the new object');
+  is_deeply (
+    [ sort $art_obj->artists->get_column ('name')->all ],
+    [ 'billy the kid', 'cowboy joe' ],
+    'Artists named correctly when queried via object',
+  );
+
+  my $artwork = $schema->resultset('Artwork')->search (
+    { 'cd.title' => 'Music to code by until the cows come home' },
+    { join => 'cd' },
+  )->single;
+  is ($artwork->artists->count, 2, 'Correct artwork creator count via a new search');
+  is_deeply (
+    [ sort $artwork->artists->get_column ('name')->all ],
+    [ 'billy the kid', 'cowboy joe' ],
+    'Artists named correctly queried via a new search',
+  );
+};
+diag $@ if $@;
+
+diag '* Nested find_or_create';
 eval {
   my $newartist2 = $schema->resultset('Artist')->find_or_create({ 
     name => 'Fred 3',
@@ -277,7 +410,7 @@ eval {
 };
 diag $@ if $@;
 
-# multiple same level has_many create
+diag '* Multiple same level has_many create';
 eval {
   my $artist2 = $schema->resultset('Artist')->create({
     name => 'Fred 4',
@@ -299,7 +432,7 @@ eval {
 };
 diag $@ if $@;
 
-# first create_related pass
+diag '* First create_related pass';
 eval {
        my $artist = $schema->resultset('Artist')->first;
        
@@ -333,7 +466,7 @@ eval {
 };
 diag $@ if $@;
 
-# second create_related with same arguments
+diag '* second create_related with same arguments';
 eval {
        my $artist = $schema->resultset('Artist')->first;
        
@@ -370,7 +503,7 @@ eval {
 };
 diag $@ if $@;
 
-# create of parents of a record linker table
+diag '* create of parents of a record linker table';
 eval {
   my $cdp = $schema->resultset('CD_to_Producer')->create({
     cd => { artist => 1, title => 'foo', year => 2000 },
@@ -380,6 +513,8 @@ eval {
 };
 diag $@ if $@;
 
+TODO: {
+local $TODO = 'Next 2 evals are NOT supposed to work, jnaps code will be torn to bits in another branch';
 #SPECIAL_CASE
 eval {
   my $kurt_cobain = { name => 'Kurt Cobain' };
@@ -417,9 +552,10 @@ eval {
   is($a->cds && $a->cds->first->title, 'The Wall', 'CD insertion ok');
 };
 diag $@ if $@;
+}
 
-## Create foreign key col obj including PK
-## See test 20 in 66relationships.t
+
+diag '* Create foreign key col obj including PK (See test 20 in 66relationships.t)';
 eval {
   my $new_cd_hashref = { 
     cdid => 27, 
@@ -447,7 +583,7 @@ eval {
 };
 is($@, '', 'new cd created without clash on related artist');
 
-# Make sure exceptions from errors in created rels propogate
+diag '* Make sure exceptions from errors in created rels propogate';
 eval {
     my $t = $schema->resultset("Track")->new({ cd => { artist => undef } });
     #$t->cd($t->new_related('cd', { artist => undef } ) );
@@ -456,7 +592,7 @@ eval {
 };
 like($@, qr/cd.artist may not be NULL/, "Exception propogated properly");
 
-# Test multi create over many_to_many
+diag '* Test multi create over many_to_many';
 eval {
   $schema->resultset('CD')->create ({
     artist => {
@@ -475,217 +611,4 @@ eval {
   is ($m2m_cd->first->producers->first->name, 'Cowboy Neal', 'Correct producer row created');
 };
 
-# and some insane multicreate 
-# (should work, despite the fact that no one will probably use it this way)
-
-# first count how many rows do we initially have
-my $counts;
-$counts->{$_} = $schema->resultset($_)->count for qw/Artist CD Genre Producer Tag/;
-
-# do the crazy create
-eval {
-  $schema->resultset('CD')->create ({
-    artist => {
-      name => 'james',
-    },
-    title => 'Greatest hits 1',
-    year => '2012',
-    genre => {
-      name => '"Greatest" collections',
-    },
-    tags => [
-      { tag => 'A' },
-      { tag => 'B' },
-    ],
-    cd_to_producer => [
-      {
-        producer => {
-          name => 'bob',
-          producer_to_cd => [
-            {
-              cd => { 
-                artist => {
-                  name => 'lars',
-                  cds => [
-                    {
-                      title => 'Greatest hits 2',
-                      year => 2012,
-                      genre => {
-                        name => '"Greatest" collections',
-                      },
-                      tags => [
-                        { tag => 'A' },
-                        { tag => 'B' },
-                      ],
-                      # This cd is created via artist so it doesn't know about producers
-                      cd_to_producer => [
-                        # if we specify 'bob' here things bomb
-                        # as the producer attached to Greatest Hits 1 is
-                        # already created, but not yet inserted.
-                        # Maybe this can be fixed, but things are hairy
-                        # enough already.
-                        #
-                        #{ producer => { name => 'bob' } },
-                        { producer => { name => 'paul' } },
-                        { producer => {
-                          name => 'flemming',
-                          producer_to_cd => [
-                            { cd => {
-                              artist => {
-                                name => 'kirk',
-                                cds => [
-                                  {
-                                    title => 'Greatest hits 3',
-                                    year => 2012,
-                                    genre => {
-                                      name => '"Greatest" collections',
-                                    },
-                                    tags => [
-                                      { tag => 'A' },
-                                      { tag => 'B' },
-                                    ],
-                                  },
-                                  {
-                                    title => 'Greatest hits 4',
-                                    year => 2012,
-                                    genre => {
-                                      name => '"Greatest" collections2',
-                                    },
-                                    tags => [
-                                      { tag => 'A' },
-                                      { tag => 'B' },
-                                    ],
-                                  },
-                                ],
-                              },
-                              title => 'Greatest hits 5',
-                              year => 2013,
-                              genre => {
-                                name => '"Greatest" collections2',
-                              },
-                            }},
-                          ],
-                        }},
-                      ],
-                    },
-                  ],
-                },
-                title => 'Greatest hits 6',
-                year => 2012,
-                genre => {
-                  name => '"Greatest" collections',
-                },
-                tags => [
-                  { tag => 'A' },
-                  { tag => 'B' },
-                ],
-              },
-            },
-            {
-              cd => { 
-                artist => {
-                  name => 'lars',    # should already exist
-                  # even though the artist 'name' is not uniquely constrained
-                  # find_or_create will arguably DWIM 
-                },
-                title => 'Greatest hits 7',
-                year => 2013,
-              },
-            },
-          ],
-        },
-      },
-    ],
-  });
-
-  is ($schema->resultset ('Artist')->count, $counts->{Artist} + 3, '3 new artists created');
-  is ($schema->resultset ('Genre')->count, $counts->{Genre} + 2, '2 additional genres created');
-  is ($schema->resultset ('Producer')->count, $counts->{Producer} + 3, '3 new producer');
-  is ($schema->resultset ('CD')->count, $counts->{CD} + 7, '7 new CDs');
-  is ($schema->resultset ('Tag')->count, $counts->{Tag} + 10, '10 new Tags');
-
-  my $cd_rs = $schema->resultset ('CD')
-    ->search ({ title => { -like => 'Greatest hits %' }}, { order_by => 'title'} );
-  is ($cd_rs->count, 7, '7 greatest hits created');
-
-  my $cds_2012 = $cd_rs->search ({ year => 2012});
-  is ($cds_2012->count, 5, '5 CDs created in 2012');
-
-  is (
-    $cds_2012->search(
-      { 'tags.tag' => { -in => [qw/A B/] } },
-      { join => 'tags', group_by => 'me.cdid' }
-    ),
-    5,
-    'All 10 tags were pairwise distributed between 5 year-2012 CDs'
-  );
-
-  my $paul_prod = $cd_rs->search (
-    { 'producer.name' => 'paul'},
-    { join => { cd_to_producer => 'producer' } }
-  );
-  is ($paul_prod->count, 1, 'Paul had 1 production');
-  my $pauls_cd = $paul_prod->single;
-  is ($pauls_cd->cd_to_producer->count, 2, 'Paul had one co-producer');
-  is (
-    $pauls_cd->search_related ('cd_to_producer',
-      { 'producer.name' => 'flemming'},
-      { join => 'producer' }
-    )->count,
-    1,
-    'The second producer is flemming',
-  );
-
-  my $kirk_cds = $cd_rs->search ({ 'artist.name' => 'kirk' }, { join => 'artist' });
-  is ($kirk_cds, 3, 'Kirk had 3 CDs');
-  is (
-    $kirk_cds->search (
-      { 'cd_to_producer.cd' => { '!=', undef } },
-      { join => 'cd_to_producer' },
-    ),
-    1,
-    'Kirk had a producer only on one cd',
-  );
-
-  my $lars_cds = $cd_rs->search ({ 'artist.name' => 'lars' }, { join => 'artist' });
-  is ($lars_cds->count, 3, 'Lars had 3 CDs');
-  is (
-    $lars_cds->search (
-      { 'cd_to_producer.cd' => undef },
-      { join => 'cd_to_producer' },
-    ),
-    0,
-    'Lars always had a producer',
-  );
-  is (
-    $lars_cds->search_related ('cd_to_producer',
-      { 'producer.name' => 'flemming'},
-      { join => 'producer' }
-    )->count,
-    1,
-    'Lars produced 1 CD with flemming',
-  );
-  is (
-    $lars_cds->search_related ('cd_to_producer',
-      { 'producer.name' => 'bob'},
-      { join => 'producer' }
-    )->count,
-    2,
-    'Lars produced 2 CDs with bob',
-  );
-
-  my $bob_prod = $cd_rs->search (
-    { 'producer.name' => 'bob'},
-    { join => { cd_to_producer => 'producer' } }
-  );
-  is ($bob_prod->count, 3, 'Bob produced a total of 3 CDs');
-
-  is (
-    $bob_prod->search ({ 'artist.name' => 'james' }, { join => 'artist' })->count,
-    1,
-    "Bob produced james' only CD",
-  );
-};
-diag $@ if $@;
-
 1;
diff --git a/t/96multi_create/cd_single.t b/t/96multi_create/cd_single.t
new file mode 100644 (file)
index 0000000..53825b8
--- /dev/null
@@ -0,0 +1,35 @@
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+eval {
+  my $cd = $schema->resultset('CD')->first;
+  my $track = $schema->resultset('Track')->new_result({
+    cd => $cd,
+    position => 77,  # some day me might test this with Ordered
+    title => 'Multicreate rocks',
+    cd_single => {
+      artist => $cd->artist,
+      year => 2008,
+      title => 'Disemboweling MultiCreate',
+    },
+  });
+
+  isa_ok ($track, 'DBICTest::Track', 'Main Track object created');
+
+  $track->insert;
+
+  ok(1, 'created track');
+
+  is($track->title, 'Multicreate rocks', 'Correct Track title');
+
+  my $single = $track->cd_single;
+
+  ok($single->cdid, 'Got cdid');
+};
diff --git a/t/96multi_create_new.t b/t/96multi_create_new.t
new file mode 100644 (file)
index 0000000..909419f
--- /dev/null
@@ -0,0 +1,49 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan 'no_plan';
+
+my $schema = DBICTest->init_schema();
+
+# Test various new() invocations - this is all about backcompat, making 
+# sure that insert() still works as expected by legacy code.
+#
+# What we essentially do is multi-instantiate objects, making sure nothing
+# gets inserted. Then we add some more objects to the mix either via
+# new_related() or by setting an accessor directly (or both) - again
+# expecting no inserts. Then after calling insert() on the starter object
+# we expect everything supplied to new() to get inserted, as well as any
+# relations whose PK's are necessary to complete the objects supplied
+# to new(). All other objects should be insert()able afterwards too.
+
+
+my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode' });
+my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave in Silence', 'year' => 1982});
+eval {
+       $new_artist->insert;
+       $new_related_cd->insert;
+};
+is ($@, '', 'Staged insertion successful');
+ok($new_artist->in_storage, 'artist inserted');
+ok($new_related_cd->in_storage, 'new_related_cd inserted');
+
+
+my $new_cd = $schema->resultset("CD")->new_result({});
+my $new_related_artist = $new_cd->new_related('artist', { 'name' => 'Marillion',});
+lives_ok (
+    sub {
+       $new_related_artist->insert;
+       $new_cd->title( 'Misplaced Childhood' );
+       $new_cd->year ( 1985 );
+       $new_cd->artist( $new_related_artist );  # For exact backward compatibility
+       $new_cd->insert;
+    },
+    'Reversed staged insertion successful'
+);
+ok($new_related_artist->in_storage, 'related artist inserted');
+ok($new_cd->in_storage, 'cd inserted');
diff --git a/t/96multi_create_torture.t b/t/96multi_create_torture.t
new file mode 100644 (file)
index 0000000..f3a62d5
--- /dev/null
@@ -0,0 +1,226 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan tests => 19;
+
+# an insane multicreate 
+# (should work, despite the fact that no one will probably use it this way)
+
+my $schema = DBICTest->init_schema();
+
+# first count how many rows do we initially have
+my $counts;
+$counts->{$_} = $schema->resultset($_)->count for qw/Artist CD Genre Producer Tag/;
+
+# do the crazy create
+eval {
+  $schema->resultset('CD')->create ({
+    artist => {
+      name => 'james',
+    },
+    title => 'Greatest hits 1',
+    year => '2012',
+    genre => {
+      name => '"Greatest" collections',
+    },
+    tags => [
+      { tag => 'A' },
+      { tag => 'B' },
+    ],
+    cd_to_producer => [
+      {
+        producer => {
+          name => 'bob',
+          producer_to_cd => [
+            {
+              cd => { 
+                artist => {
+                  name => 'lars',
+                  cds => [
+                    {
+                      title => 'Greatest hits 2',
+                      year => 2012,
+                      genre => {
+                        name => '"Greatest" collections',
+                      },
+                      tags => [
+                        { tag => 'A' },
+                        { tag => 'B' },
+                      ],
+                      # This cd is created via artist so it doesn't know about producers
+                      cd_to_producer => [
+                        # if we specify 'bob' here things bomb
+                        # as the producer attached to Greatest Hits 1 is
+                        # already created, but not yet inserted.
+                        # Maybe this can be fixed, but things are hairy
+                        # enough already.
+                        #
+                        #{ producer => { name => 'bob' } },
+                        { producer => { name => 'paul' } },
+                        { producer => {
+                          name => 'flemming',
+                          producer_to_cd => [
+                            { cd => {
+                              artist => {
+                                name => 'kirk',
+                                cds => [
+                                  {
+                                    title => 'Greatest hits 3',
+                                    year => 2012,
+                                    genre => {
+                                      name => '"Greatest" collections',
+                                    },
+                                    tags => [
+                                      { tag => 'A' },
+                                      { tag => 'B' },
+                                    ],
+                                  },
+                                  {
+                                    title => 'Greatest hits 4',
+                                    year => 2012,
+                                    genre => {
+                                      name => '"Greatest" collections2',
+                                    },
+                                    tags => [
+                                      { tag => 'A' },
+                                      { tag => 'B' },
+                                    ],
+                                  },
+                                ],
+                              },
+                              title => 'Greatest hits 5',
+                              year => 2013,
+                              genre => {
+                                name => '"Greatest" collections2',
+                              },
+                            }},
+                          ],
+                        }},
+                      ],
+                    },
+                  ],
+                },
+                title => 'Greatest hits 6',
+                year => 2012,
+                genre => {
+                  name => '"Greatest" collections',
+                },
+                tags => [
+                  { tag => 'A' },
+                  { tag => 'B' },
+                ],
+              },
+            },
+            {
+              cd => { 
+                artist => {
+                  name => 'lars',    # should already exist
+                  # even though the artist 'name' is not uniquely constrained
+                  # find_or_create will arguably DWIM 
+                },
+                title => 'Greatest hits 7',
+                year => 2013,
+              },
+            },
+          ],
+        },
+      },
+    ],
+  });
+
+  is ($schema->resultset ('Artist')->count, $counts->{Artist} + 3, '3 new artists created');
+  is ($schema->resultset ('Genre')->count, $counts->{Genre} + 2, '2 additional genres created');
+  is ($schema->resultset ('Producer')->count, $counts->{Producer} + 3, '3 new producer');
+  is ($schema->resultset ('CD')->count, $counts->{CD} + 7, '7 new CDs');
+  is ($schema->resultset ('Tag')->count, $counts->{Tag} + 10, '10 new Tags');
+
+  my $cd_rs = $schema->resultset ('CD')
+    ->search ({ title => { -like => 'Greatest hits %' }}, { order_by => 'title'} );
+  is ($cd_rs->count, 7, '7 greatest hits created');
+
+  my $cds_2012 = $cd_rs->search ({ year => 2012});
+  is ($cds_2012->count, 5, '5 CDs created in 2012');
+
+  is (
+    $cds_2012->search(
+      { 'tags.tag' => { -in => [qw/A B/] } },
+      { join => 'tags', group_by => 'me.cdid' }
+    ),
+    5,
+    'All 10 tags were pairwise distributed between 5 year-2012 CDs'
+  );
+
+  my $paul_prod = $cd_rs->search (
+    { 'producer.name' => 'paul'},
+    { join => { cd_to_producer => 'producer' } }
+  );
+  is ($paul_prod->count, 1, 'Paul had 1 production');
+  my $pauls_cd = $paul_prod->single;
+  is ($pauls_cd->cd_to_producer->count, 2, 'Paul had one co-producer');
+  is (
+    $pauls_cd->search_related ('cd_to_producer',
+      { 'producer.name' => 'flemming'},
+      { join => 'producer' }
+    )->count,
+    1,
+    'The second producer is flemming',
+  );
+
+  my $kirk_cds = $cd_rs->search ({ 'artist.name' => 'kirk' }, { join => 'artist' });
+  is ($kirk_cds, 3, 'Kirk had 3 CDs');
+  is (
+    $kirk_cds->search (
+      { 'cd_to_producer.cd' => { '!=', undef } },
+      { join => 'cd_to_producer' },
+    ),
+    1,
+    'Kirk had a producer only on one cd',
+  );
+
+  my $lars_cds = $cd_rs->search ({ 'artist.name' => 'lars' }, { join => 'artist' });
+  is ($lars_cds->count, 3, 'Lars had 3 CDs');
+  is (
+    $lars_cds->search (
+      { 'cd_to_producer.cd' => undef },
+      { join => 'cd_to_producer' },
+    ),
+    0,
+    'Lars always had a producer',
+  );
+  is (
+    $lars_cds->search_related ('cd_to_producer',
+      { 'producer.name' => 'flemming'},
+      { join => 'producer' }
+    )->count,
+    1,
+    'Lars produced 1 CD with flemming',
+  );
+  is (
+    $lars_cds->search_related ('cd_to_producer',
+      { 'producer.name' => 'bob'},
+      { join => 'producer' }
+    )->count,
+    2,
+    'Lars produced 2 CDs with bob',
+  );
+
+  my $bob_prod = $cd_rs->search (
+    { 'producer.name' => 'bob'},
+    { join => { cd_to_producer => 'producer' } }
+  );
+  is ($bob_prod->count, 3, 'Bob produced a total of 3 CDs');
+
+  is (
+    $bob_prod->search ({ 'artist.name' => 'james' }, { join => 'artist' })->count,
+    1,
+    "Bob produced james' only CD",
+  );
+};
+diag $@ if $@;
+
+1;
index a35d54e..2ff55c6 100644 (file)
@@ -22,6 +22,7 @@ __PACKAGE__->load_classes(qw/
   { 'DBICTest::Schema' => [qw/
     LinerNotes
     Artwork
+    Artwork_to_Artist
     Image
     Lyrics
     LyricVersion
index c575374..959b4fc 100644 (file)
@@ -53,6 +53,12 @@ __PACKAGE__->has_many(
   { cascade_copy => 0 } # this would *so* not make sense
 );
 
+__PACKAGE__->has_many(
+    artist_to_artwork => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
+);
+__PACKAGE__->many_to_many('artworks', 'artist_to_artwork', 'artwork');
+
+
 sub sqlt_deploy_hook {
   my ($self, $sqlt_table) = @_;
 
index f6e00d2..10e07ce 100644 (file)
@@ -1,4 +1,4 @@
-package # hide from PAUSE 
+package # hide from PAUSE
     DBICTest::Schema::Artwork;
 
 use base qw/DBIx::Class::Core/;
@@ -13,4 +13,7 @@ __PACKAGE__->set_primary_key('cd_id');
 __PACKAGE__->belongs_to('cd', 'DBICTest::Schema::CD', 'cd_id');
 __PACKAGE__->has_many('images', 'DBICTest::Schema::Image', 'artwork_id');
 
+__PACKAGE__->has_many('artwork_to_artist', 'DBICTest::Schema::Artwork_to_Artist', 'artwork_cd_id');
+__PACKAGE__->many_to_many('artists', 'artwork_to_artist', 'artist');
+
 1;
diff --git a/t/lib/DBICTest/Schema/Artwork_to_Artist.pm b/t/lib/DBICTest/Schema/Artwork_to_Artist.pm
new file mode 100644 (file)
index 0000000..0d832ca
--- /dev/null
@@ -0,0 +1,21 @@
+package # hide from PAUSE
+    DBICTest::Schema::Artwork_to_Artist;
+
+use base qw/DBIx::Class::Core/;
+
+__PACKAGE__->table('artwork_to_artist');
+__PACKAGE__->add_columns(
+  'artwork_cd_id' => {
+    data_type => 'integer',
+    is_foreign_key => 1,
+  },
+  'artist_id' => {
+    data_type => 'integer',
+    is_foreign_key => 1,
+  },
+);
+__PACKAGE__->set_primary_key(qw/artwork_cd_id artist_id/);
+__PACKAGE__->belongs_to('artwork', 'DBICTest::Schema::Artwork', 'artwork_cd_id');
+__PACKAGE__->belongs_to('artist', 'DBICTest::Schema::Artist', 'artist_id');
+
+1;
index ebc10cd..b364cb4 100644 (file)
@@ -1,6 +1,6 @@
 -- 
 -- Created by SQL::Translator::Producer::SQLite
--- Created on Sat Jan 17 19:40:47 2009
+-- Created on Sat Jan 24 19:42:15 2009
 -- 
 BEGIN TRANSACTION;
 
@@ -38,6 +38,18 @@ CREATE TABLE cd_artwork (
 CREATE INDEX cd_artwork_idx_cd_id_cd_artwor ON cd_artwork (cd_id);
 
 --
+-- Table: artwork_to_artist
+--
+CREATE TABLE artwork_to_artist (
+  artwork_cd_id integer NOT NULL,
+  artist_id integer NOT NULL,
+  PRIMARY KEY (artwork_cd_id, artist_id)
+);
+
+CREATE INDEX artwork_to_artist_idx_artist_id_artwork_to_arti ON artwork_to_artist (artist_id);
+CREATE INDEX artwork_to_artist_idx_artwork_cd_id_artwork_to_ ON artwork_to_artist (artwork_cd_id);
+
+--
 -- Table: bindtype_test
 --
 CREATE TABLE bindtype_test (