[Bast-commits] r4808 - in DBIx-Class/0.08/branches/view_support: . lib/DBIx lib/DBIx/Class lib/DBIx/Class/Manual lib/DBIx/Class/Relationship lib/DBIx/Class/Schema lib/DBIx/Class/Storage/DBI t t/cdbi-DeepAbstractSearch t/cdbi-t t/lib t/lib/DBICTest t/lib/DBICTest/Schema

wreis at dev.catalyst.perl.org wreis at dev.catalyst.perl.org
Tue Sep 16 12:38:37 BST 2008


Author: wreis
Date: 2008-09-16 12:38:37 +0100 (Tue, 16 Sep 2008)
New Revision: 4808

Added:
   DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema/Genre.pm
Modified:
   DBIx-Class/0.08/branches/view_support/
   DBIx-Class/0.08/branches/view_support/Changes
   DBIx-Class/0.08/branches/view_support/lib/DBIx/Class.pm
   DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Manual/Cookbook.pod
   DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Manual/FAQ.pod
   DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Relationship.pm
   DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Relationship/Base.pm
   DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/ResultSource.pm
   DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Row.pm
   DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Schema/Versioned.pm
   DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Storage/DBI/Replicated.pm
   DBIx-Class/0.08/branches/view_support/t/18inserterror.t
   DBIx-Class/0.08/branches/view_support/t/50fork.t
   DBIx-Class/0.08/branches/view_support/t/51threads.t
   DBIx-Class/0.08/branches/view_support/t/51threadtxn.t
   DBIx-Class/0.08/branches/view_support/t/60core.t
   DBIx-Class/0.08/branches/view_support/t/66relationship.t
   DBIx-Class/0.08/branches/view_support/t/73oracle_inflate.t
   DBIx-Class/0.08/branches/view_support/t/74mssql.t
   DBIx-Class/0.08/branches/view_support/t/77prefetch.t
   DBIx-Class/0.08/branches/view_support/t/91debug.t
   DBIx-Class/0.08/branches/view_support/t/93single_accessor_object.t
   DBIx-Class/0.08/branches/view_support/t/96file_column.t
   DBIx-Class/0.08/branches/view_support/t/96multi_create.t
   DBIx-Class/0.08/branches/view_support/t/cdbi-DeepAbstractSearch/01_search.t
   DBIx-Class/0.08/branches/view_support/t/cdbi-t/15-accessor.t
   DBIx-Class/0.08/branches/view_support/t/cdbi-t/22-deflate_order.t
   DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema.pm
   DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema/CD.pm
   DBIx-Class/0.08/branches/view_support/t/lib/sqlite.sql
Log:
 r23937 at tabor (orig r4773):  matthewt | 2008-08-25 22:36:09 -0300
 fix related resultsets and multi-create
 r23946 at tabor (orig r4778):  jgoulah | 2008-08-26 17:43:04 -0300
 virtual method so user can create upgrade path across multiple versions
 r26512 at tabor (orig r4785):  jnapiorkowski | 2008-08-27 10:40:07 -0300
 fixed braindead typo in docs telling people to use a version of Moose that does not exist yet
 r26513 at tabor (orig r4786):  jgoulah | 2008-08-27 11:15:07 -0300
 adding contact details per lukes request; added docs on how to get db/schema version
 r26514 at tabor (orig r4787):  matthewt | 2008-08-28 12:50:58 -0300
 doh
 r26515 at tabor (orig r4788):  ribasushi | 2008-08-28 13:12:16 -0300
 doh2
 r26516 at tabor (orig r4789):  ribasushi | 2008-08-28 19:16:26 -0300
 Forgot to modify Changes - looks good to castaway :D
 r26517 at tabor (orig r4791):  semifor | 2008-08-30 22:55:17 -0300
 Adedd TODO test demonstrating $rs->delete failure for file_columns.
 r26518 at tabor (orig r4792):  castaway | 2008-08-31 09:01:25 -0300
 Added doc patches from g about cascade_delete
 
 r26519 at tabor (orig r4794):  g | 2008-09-03 09:02:52 -0300
 Fixed wrong field names: cd.cdid -> cd.id, artist.artistid ->
 artist.id.
 Removed use of table aliases in examples.
 Fixed redundant & inconsistent brackets on ON clauses in SQL examples.
 Added info about multiple joins as well as multi-step joins.
 Fixed where 'JOIN' was used instead of 'LEFT JOIN'.
 
 r26566 at tabor (orig r4795):  ribasushi | 2008-09-09 19:56:22 -0300
 Align self-deploying tests with the CD schema changes introduced by r4773
 r26567 at tabor (orig r4796):  ribasushi | 2008-09-09 19:59:42 -0300
 Consistent skip messages throughout the test suite (consists of a simple reordering of prerequisite eval checks)
 r26671 at tabor (orig r4805):  matthewt | 2008-09-13 13:28:48 -0300
 use unlike in test to make error report more useful
 r26672 at tabor (orig r4807):  rafl | 2008-09-15 16:49:18 -0300
 Add myself to CONTRIBUTORS.



Property changes on: DBIx-Class/0.08/branches/view_support
___________________________________________________________________
Name: svk:merge
   - 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioning:4578
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:4767
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510
   + 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioning:4578
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:4807
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510

Modified: DBIx-Class/0.08/branches/view_support/Changes
===================================================================
--- DBIx-Class/0.08/branches/view_support/Changes	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/Changes	2008-09-16 11:38:37 UTC (rev 4808)
@@ -1,6 +1,16 @@
 Revision history for DBIx::Class
+
+        - Fixed up related resultsets and multi-create
         - Fixed superfluous connection in ODBC::_rebless
         - Fixed undef PK for first insert in ODBC::Microsoft_SQL_Server
+        - Added virtual method to Versioned so a user can create upgrade 
+          path across multiple versions (jgoulah)
+        - Better (and marginally faster) implementation of the HashRefInflator
+          hash construction algorithm
+        - Added an option for HashRefInflator to inflate any inflatable
+          values in the resulting hashref
+        - Allow explicit specification of ON DELETE/ON UPDATE constraints
+          when using the SQLT parser
 
 0.08099_04 2008-07-24 01:00:00
         - Functionality to storage to enable a sub to be run without FK checks

Modified: DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Manual/Cookbook.pod
===================================================================
--- DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Manual/Cookbook.pod	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Manual/Cookbook.pod	2008-09-16 11:38:37 UTC (rev 4808)
@@ -216,15 +216,15 @@
     {},
     {
       join     => [qw/ cds /],
-      select   => [ 'name', { count => 'cds.cdid' } ],
+      select   => [ 'name', { count => 'cds.id' } ],
       as       => [qw/ name cd_count /],
       group_by => [qw/ name /]
     }
   );
 
   # Equivalent SQL:
-  # SELECT name, COUNT( cds.cdid ) FROM artist me
-  # LEFT JOIN cd cds ON ( cds.artist = me.artistid )
+  # SELECT name, COUNT( cd.id ) FROM artist
+  # LEFT JOIN cd ON artist.id = cd.artist
   # GROUP BY name
 
 Please see L<DBIx::Class::ResultSet/ATTRIBUTES> documentation if you
@@ -312,7 +312,7 @@
       'artist.name' => 'Bob Marley'    
     },
     {
-      join => [qw/artist/], # join the artist table
+      join => 'artist', # join the artist table
     }
   );
 
@@ -329,7 +329,7 @@
       'artist.name' => 'Bob Marley'
     },
     {
-      join     => [qw/ artist /],
+      join     => 'artist',
       order_by => [qw/ artist.name /]
     }
   );
@@ -370,9 +370,9 @@
       'artist.name' => 'Bob Marley'
     },
     {
-      join     => [qw/ artist /],
+      join     => 'artist',
       order_by => [qw/ artist.name /],
-      prefetch => [qw/ artist /] # return artist data too!
+      prefetch => 'artist' # return artist data too!
     }
   );
 
@@ -399,6 +399,34 @@
 definitely use data from a related table. Pre-fetching related tables when you
 only need columns from the main table will make performance worse!
 
+=head2 Multiple joins
+
+In the examples above, the C<join> attribute was a scalar.  If you
+pass an array reference instead, you can join to multiple tables.  In
+this example, we want to limit the search further, using
+C<LinerNotes>:
+
+  # Relationships defined elsewhere:
+  # CD->belongs_to('artist' => 'Artist');
+  # CD->has_one('liner_notes' => 'LinerNotes', 'cd');
+  my $rs = $schema->resultset('CD')->search(
+    {
+      'artist.name' => 'Bob Marley'
+      'liner_notes.notes' => { 'like', '%some text%' },
+    },
+    {
+      join     => [qw/ artist liner_notes /],
+      order_by => [qw/ artist.name /],
+    }
+  );
+
+  # Equivalent SQL:
+  # SELECT cd.*, artist.*, liner_notes.* FROM cd
+  # JOIN artist ON cd.artist = artist.id
+  # JOIN liner_notes ON cd.id = liner_notes.cd
+  # WHERE artist.name = 'Bob Marley'
+  # ORDER BY artist.name
+
 =head2 Multi-step joins
 
 Sometimes you want to join more than one relationship deep. In this example,
@@ -422,8 +450,8 @@
 
   # Equivalent SQL:
   # SELECT artist.* FROM artist
-  # JOIN ( cd ON artist.id = cd.artist )
-  # JOIN ( liner_notes ON cd.id = liner_notes.cd )
+  # LEFT JOIN cd ON artist.id = cd.artist
+  # LEFT JOIN liner_notes ON cd.id = liner_notes.cd
   # WHERE liner_notes.notes LIKE '%some text%'
 
 Joins can be nested to an arbitrary level. So if we decide later that we
@@ -449,12 +477,39 @@
 
   # Equivalent SQL:
   # SELECT artist.* FROM artist
-  # JOIN ( cd ON artist.id = cd.artist )
-  # JOIN ( liner_notes ON cd.id = liner_notes.cd )
-  # JOIN ( author ON author.id = liner_notes.author )
+  # LEFT JOIN cd ON artist.id = cd.artist
+  # LEFT JOIN liner_notes ON cd.id = liner_notes.cd
+  # LEFT JOIN author ON author.id = liner_notes.author
   # WHERE liner_notes.notes LIKE '%some text%'
   # AND author.name = 'A. Writer'
 
+=head2 Multi-step and multiple joins
+
+With various combinations of array and hash references, you can join
+tables in any combination you desire.  For example, to join Artist to
+CD and Concert, and join CD to LinerNotes:
+
+  # Relationships defined elsewhere:
+  # Artist->has_many('concerts' => 'Concert', 'artist');
+
+  my $rs = $schema->resultset('Artist')->search(
+    { },
+    {
+      join => [
+        {
+          cds => 'liner_notes'
+        },
+        'concerts'
+      ],
+    }
+  );
+
+  # Equivalent SQL:
+  # SELECT artist.* FROM artist
+  # LEFT JOIN cd ON artist.id = cd.artist
+  # LEFT JOIN liner_notes ON cd.id = liner_notes.cd
+  # LEFT JOIN concert ON artist.id = concert.artist
+
 =head2 Multi-step prefetch
 
 From 0.04999_05 onwards, C<prefetch> can be nested more than one relationship
@@ -471,8 +526,8 @@
 
   # Equivalent SQL:
   # SELECT tag.*, cd.*, artist.* FROM tag
-  # JOIN cd ON tag.cd = cd.cdid
-  # JOIN artist ON cd.artist = artist.artistid
+  # JOIN cd ON tag.cd = cd.id
+  # JOIN artist ON cd.artist = artist.id
 
 Now accessing our C<cd> and C<artist> relationships does not need additional
 SQL statements:

Modified: DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Manual/FAQ.pod
===================================================================
--- DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Manual/FAQ.pod	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Manual/FAQ.pod	2008-09-16 11:38:37 UTC (rev 4808)
@@ -77,7 +77,7 @@
 
 =item .. tell DBIx::Class about relationships between my tables?
 
-There are a vareity of relationship types that come pre-defined for
+There are a variety of relationship types that come pre-defined for
 you to use.  These are all listed in L<DBIx::Class::Relationship>. If
 you need a non-standard type, or more information, look in
 L<DBIx::Class::Relationship::Base>.
@@ -113,13 +113,20 @@
 
 Read the documentation on L<DBIx::Class::Relationship/many_to_many>.
 
-=item .. stop DBIx::Class from attempting to cascade deletes on my has_many relationships?
+=item .. stop DBIx::Class from attempting to cascade deletes on my has_many and might_have relationships?
 
 By default, DBIx::Class cascades deletes and updates across
-C<has_many> relationships. If your database already does this (and
-that is probably better), turn it off by supplying C<< cascade_delete => 0 >>
-in the relationship attributes. See L<DBIx::Class::Relationship::Base>.
+C<has_many> and C<might_have> relationships. You can disable this
+behaviour on a per-relationship basis by supplying
+C<< cascade_delete => 0 >> in the relationship attributes.
 
+The cascaded operations are performed after the requested delete or
+update, so if your database has a constraint on the relationship, it
+will have deleted/updated the related records or raised an exception
+before DBIx::Class gets to perform the cascaded operation.
+
+See L<DBIx::Class::Relationship>.
+
 =item .. use a relationship?
 
 Use its name. An accessor is created using the name. See examples in
@@ -294,11 +301,11 @@
 
 Then call L<DBIx::Class::ResultSet/slice> and ask it only to return 1 row:
 
-  ->slice(0,1)
+  ->slice(0)
 
 These two calls can be combined into a single statement:
 
-  ->search->(undef, { order_by => "id DESC" })->slice(0,1)
+  ->search->(undef, { order_by => "id DESC" })->slice(0)
 
 Why slice instead of L<DBIx::Class::ResultSet/first> or L<DBIx::Class::ResultSet/single>?
 If supported by the database, slice will use LIMIT/OFFSET to hint to the database that we

Modified: DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Relationship/Base.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Relationship/Base.pm	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Relationship/Base.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -190,11 +190,18 @@
       $rel_obj->{cond}, $rel, $self
     );
     if (ref $cond eq 'ARRAY') {
-      $cond = [ map { my $hash;
-        foreach my $key (keys %$_) {
-          my $newkey = $key =~ /\./ ? "me.$key" : $key;
-          $hash->{$newkey} = $_->{$key};
-        }; $hash } @$cond ];
+      $cond = [ map {
+        if (ref $_ eq 'HASH') {
+          my $hash;
+          foreach my $key (keys %$_) {
+            my $newkey = $key =~ /\./ ? "me.$key" : $key;
+            $hash->{$newkey} = $_->{$key};
+          }
+          $hash;
+        } else {
+          $_;
+        }
+      } @$cond ];
     } else {
       foreach my $key (grep { ! /\./ } keys %$cond) {
         $cond->{"me.$key"} = delete $cond->{$key};

Modified: DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Relationship.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Relationship.pm	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Relationship.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -330,10 +330,13 @@
 
 If you delete an object in a class with a C<has_many> relationship, all
 the related objects will be deleted as well.  To turn this behaviour off,
-pass C<< cascade_delete => 0 >> in the C<attr> hashref. However, any
-database-level cascade or restrict will take precedence over a
-DBIx-Class-based cascading delete.
+pass C<< cascade_delete => 0 >> in the C<$attr> hashref.
 
+The cascaded operations are performed after the requested delete or
+update, so if your database has a constraint on the relationship, it
+will have deleted/updated the related records or raised an exception
+before DBIx::Class gets to perform the cascaded operation.
+
 If you copy an object in a class with a C<has_many> relationship, all
 the related objects will be copied as well. To turn this behaviour off,
 pass C<< cascade_copy => 0 >> in the C<$attr> hashref. The behaviour
@@ -414,9 +417,13 @@
 If you update or delete an object in a class with a C<might_have>
 relationship, the related object will be updated or deleted as well. To
 turn off this behavior, add C<< cascade_delete => 0 >> to the C<$attr>
-hashref. Any database-level update or delete constraints will override
-this behavior.
+hashref.
 
+The cascaded operations are performed after the requested delete or
+update, so if your database has a constraint on the relationship, it
+will have deleted/updated the related records or raised an exception
+before DBIx::Class gets to perform the cascaded operation.
+
 See L<DBIx::Class::Relationship::Base> for documentation on relationship
 methods and valid relationship attributes.
 

Modified: DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/ResultSource.pm	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/ResultSource.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -780,6 +780,49 @@
   }
 }
 
+=head2 pk_depends_on
+
+=over 4
+
+=item Arguments: $relname, $rel_data
+
+=back
+
+Determines whether a relation is dependent on an object from this source
+having already been inserted. Takes the name of the relationship and a
+hashref of columns of the related object.
+
+=cut
+
+sub pk_depends_on {
+  my ($self, $relname, $rel_data) = @_;
+  my $cond = $self->relationship_info($relname)->{cond};
+
+  return 0 unless ref($cond) eq 'HASH';
+
+  # map { foreign.foo => 'self.bar' } to { bar => 'foo' }
+
+  my $keyhash = { map { my $x = $_; $x =~ s/.*\.//; $x; } reverse %$cond };
+
+  # assume anything that references our PK probably is dependent on us
+  # rather than vice versa, unless the far side is (a) defined or (b)
+  # auto-increment
+
+  my $rel_source = $self->related_source($relname);
+
+  foreach my $p ($self->primary_columns) {
+    if (exists $keyhash->{$p}) {
+      unless (defined($rel_data->{$keyhash->{$p}})
+              || $rel_source->column_info($keyhash->{$p})
+                            ->{is_auto_increment}) {
+        return 0;
+      }
+    }
+  }
+
+  return 1;
+}
+
 =head2 resolve_condition
 
 =over 4
@@ -808,7 +851,14 @@
         $self->throw_exception("Invalid rel cond val ${v}");
       if (ref $for) { # Object
         #warn "$self $k $for $v";
-        $ret{$k} = $for->get_column($v) if $for->has_column_loaded($v);
+        unless ($for->has_column_loaded($v)) {
+          if ($for->in_storage) {
+            $self->throw_exception("Column ${v} not loaded on ${for} trying to reolve relationship");
+          }
+          return [ \'1 = 0' ];
+        }
+        $ret{$k} = $for->get_column($v);
+        #$ret{$k} = $for->get_column($v) if $for->has_column_loaded($v);
         #warn %ret;
       } elsif (!defined $for) { # undef, i.e. "no object"
         $ret{$k} = undef;

Modified: DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Row.pm	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Row.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -46,6 +46,37 @@
 ## check Relationship::CascadeActions and Relationship::Accessor for compat
 ## tests!
 
+sub __new_related_find_or_new_helper {
+  my ($self, $relname, $data) = @_;
+  if ($self->__their_pk_needs_us($relname, $data)) {
+    return $self->result_source
+                ->related_source($relname)
+                ->resultset
+                ->new_result($data);
+  }
+  if ($self->result_source->pk_depends_on($relname, $data)) {
+    return $self->result_source
+                ->related_source($relname)
+                ->resultset
+                ->find_or_new($data);
+  }
+  return $self->find_or_new_related($relname, $data);
+}
+
+sub __their_pk_needs_us { # this should maybe be in resultsource.
+  my ($self, $relname, $data) = @_;
+  my $source = $self->result_source;
+  my $reverse = $source->reverse_relationship_info($relname);
+  my $rel_source = $source->related_source($relname);
+  my $us = { $self->get_columns };
+  foreach my $key (keys %$reverse) {
+    # if their primary key depends on us, then we have to
+    # just create a result and we'll fill it out afterwards
+    return 1 if $rel_source->pk_depends_on($key, $us);
+  }
+  return 0;
+}
+
 sub new {
   my ($class, $attrs) = @_;
   $class = ref $class if ref $class;
@@ -58,7 +89,9 @@
   if (my $handle = delete $attrs->{-source_handle}) {
     $new->_source_handle($handle);
   }
-  if (my $source = delete $attrs->{-result_source}) {
+
+  my $source;
+  if ($source = delete $attrs->{-result_source}) {
     $new->result_source($source);
   }
 
@@ -73,18 +106,19 @@
     foreach my $key (keys %$attrs) {
       if (ref $attrs->{$key}) {
         ## Can we extract this lot to use with update(_or .. ) ?
-        my $info = $class->relationship_info($key);
+        confess "Can't do multi-create without result source" unless $source;
+        my $info = $source->relationship_info($key);
         if ($info && $info->{attrs}{accessor}
           && $info->{attrs}{accessor} eq 'single')
         {
           my $rel_obj = delete $attrs->{$key};
           if(!Scalar::Util::blessed($rel_obj)) {
-            $rel_obj = $new->find_or_new_related($key, $rel_obj);
+            $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj);
           }
 
           $new->{_rel_in_storage} = 0 unless ($rel_obj->in_storage);
 
-          $new->set_from_related($key, $rel_obj);        
+          $new->set_from_related($key, $rel_obj) if $rel_obj->in_storage;
           $related->{$key} = $rel_obj;
           next;
         } elsif ($info && $info->{attrs}{accessor}
@@ -93,11 +127,11 @@
           my $others = delete $attrs->{$key};
           foreach my $rel_obj (@$others) {
             if(!Scalar::Util::blessed($rel_obj)) {
-              $rel_obj = $new->new_related($key, $rel_obj);
-              $new->{_rel_in_storage} = 0;
+              $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj);
             }
 
             $new->{_rel_in_storage} = 0 unless ($rel_obj->in_storage);
+            $new->set_from_related($key, $rel_obj) if $rel_obj->in_storage;
           }
           $related->{$key} = $others;
           next;
@@ -107,9 +141,9 @@
           ## 'filter' should disappear and get merged in with 'single' above!
           my $rel_obj = delete $attrs->{$key};
           if(!Scalar::Util::blessed($rel_obj)) {
-            $rel_obj = $new->find_or_new_related($key, $rel_obj);
-            $new->{_rel_in_storage} = 0 unless ($rel_obj->in_storage);
+            $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj);
           }
+          $new->{_rel_in_storage} = 0 unless ($rel_obj->in_storage);
           $inflated->{$key} = $rel_obj;
           next;
         } elsif ($class->has_column($key)
@@ -181,28 +215,10 @@
       next REL unless (Scalar::Util::blessed($rel_obj)
                        && $rel_obj->isa('DBIx::Class::Row'));
 
-      my $cond = $source->relationship_info($relname)->{cond};
+      next REL unless $source->pk_depends_on(
+                        $relname, { $rel_obj->get_columns }
+                      );
 
-      next REL unless ref($cond) eq 'HASH';
-
-      # map { foreign.foo => 'self.bar' } to { bar => 'foo' }
-
-      my $keyhash = { map { my $x = $_; $x =~ s/.*\.//; $x; } reverse %$cond };
-
-      # assume anything that references our PK probably is dependent on us
-      # rather than vice versa, unless the far side is (a) defined or (b)
-      # auto-increment
-
-      foreach my $p (@pri) {
-        if (exists $keyhash->{$p}) {
-          unless (defined($rel_obj->get_column($keyhash->{$p}))
-                  || $rel_obj->column_info($keyhash->{$p})
-                             ->{is_auto_increment}) {
-            next REL;
-          }
-        }
-      }
-
       $rel_obj->insert();
       $self->set_from_related($relname, $rel_obj);
       delete $related_stuff{$relname};
@@ -231,6 +247,9 @@
     $self->store_column($auto_pri[$_] => $ids[$_]) for 0 .. $#ids;
   }
 
+  $self->{_dirty_columns} = {};
+  $self->{related_resultsets} = {};
+
   if(!$self->{_rel_in_storage}) {
     ## Now do the has_many rels, that need $selfs ID.
     foreach my $relname (keys %related_stuff) {
@@ -246,7 +265,12 @@
         my $reverse = $source->reverse_relationship_info($relname);
         foreach my $obj (@cands) {
           $obj->set_from_related($_, $self) for keys %$reverse;
-          $obj->insert() unless ($obj->in_storage || $obj->result_source->resultset->search({$obj->get_columns})->count);
+          my $them = { $obj->get_columns };
+          if ($self->__their_pk_needs_us($relname, $them)) {
+            $obj = $self->find_or_create_related($relname, $them);
+          } else {
+            $obj->insert();
+          }
         }
       }
     }
@@ -254,8 +278,6 @@
   }
 
   $self->in_storage(1);
-  $self->{_dirty_columns} = {};
-  $self->{related_resultsets} = {};
   undef $self->{_orig_ident};
   return $self;
 }
@@ -723,7 +745,8 @@
 
 =cut
 
-*insert_or_update = \&update_or_insert;
+sub insert_or_update { shift->update_or_insert(@_) }
+
 sub update_or_insert {
   my $self = shift;
   return ($self->in_storage ? $self->update : $self->insert);

Modified: DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Schema/Versioned.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Schema/Versioned.pm	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Schema/Versioned.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -235,7 +235,7 @@
   if ($new_version) {
     # create versions table and version row
     $self->{vschema}->deploy;
-    $self->_set_db_version;
+    $self->_set_db_version({ version => $new_version });
   }
 }
 
@@ -251,6 +251,27 @@
   $self->install();
 }
 
+=head2 create_upgrade_path
+
+=over 4
+
+=item Arguments: { upgrade_file => $file }
+
+=back
+
+Virtual method that should be overriden to create an upgrade file. 
+This is useful in the case of upgrading across multiple versions 
+to concatenate several files to create one upgrade file.
+
+You'll probably want the db_version retrieved via $self->get_db_version
+and the schema_version which is retrieved via $self->schema_version 
+
+=cut
+
+sub create_upgrade_path {
+	## override this method
+}
+
 =head2 upgrade
 
 Call this to attempt to upgrade your database from the version it is at to the version
@@ -294,11 +315,15 @@
                                          $db_version,
                                         );
 
+  $self->create_upgrade_path({ upgrade_file => $upgrade_file });
+
   unless (-f $upgrade_file) {
     warn "Upgrade not possible, no upgrade file found ($upgrade_file), please create one\n";
     return;
   }
 
+  warn "\nDB version ($db_version) is lower than the schema version (".$self->schema_version."). Attempting upgrade.\n";
+
   # backup if necessary then apply upgrade
   $self->_filedata($self->_read_sql_file($upgrade_file));
   $self->backup() if($self->do_backup);
@@ -546,9 +571,12 @@
 
 sub _set_db_version {
   my $self = shift;
+  my ($params) = @_;
+  $params ||= {};
 
+  my $version = $params->{version} ? $params->{version} : $self->schema_version;
   my $vtable = $self->{vschema}->resultset('Table');
-  $vtable->create({ version => $self->schema_version,
+  $vtable->create({ version => $version,
                       installed => strftime("%Y-%m-%d %H:%M:%S", gmtime())
                       });
 

Modified: DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -99,7 +99,7 @@
 
 Replicated Storage has additional requirements not currently part of L<DBIx::Class>
 
-  Moose => 1.54
+  Moose => 0.54
   MooseX::AttributeHelpers => 0.12 
   Moose::Util::TypeConstraints => 0.54
   Class::MOP => 0.63

Modified: DBIx-Class/0.08/branches/view_support/lib/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/lib/DBIx/Class.pm	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/lib/DBIx/Class.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -243,6 +243,8 @@
 
 jesper: Jesper Krogh
 
+jgoulah: John Goulah <jgoulah at cpan.org>
+
 jguenther: Justin Guenther <jguenther at cpan.org>
 
 jnapiorkowski: John Napiorkowski <jjn1056 at yahoo.com>
@@ -277,8 +279,12 @@
 
 quicksilver: Jules Bean
 
+rafl: Florian Ragwitz <rafl at debian.org>
+
 rdj: Ryan D Johnson <ryan at innerfence.com>
 
+ribasushi: Peter Rabbitson <rabbit at rabbit.us>
+
 sc_: Just Another Perl Hacker
 
 scotty: Scotty Allen <scotty at scottyallen.com>

Modified: DBIx-Class/0.08/branches/view_support/t/18inserterror.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/18inserterror.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/18inserterror.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -24,6 +24,6 @@
                 ->create({ title => 'vacation in antarctica' })
        };
        like $@, qr/NULL/;  # as opposed to some other error
-       ok( $warnings !~ /uninitialized value/, "No warning from Storage" );
+       unlike( $warnings, qr/uninitialized value/, "No warning from Storage" );
 }
 

Modified: DBIx-Class/0.08/branches/view_support/t/50fork.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/50fork.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/50fork.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -34,7 +34,7 @@
     {
         local $SIG{__WARN__} = sub {};
         eval { $dbh->do("DROP TABLE cd") };
-        $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(255) NOT NULL UNIQUE, year VARCHAR(255));");
+        $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER);");
     }
 
     $schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 });

Modified: DBIx-Class/0.08/branches/view_support/t/51threads.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/51threads.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/51threads.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -44,7 +44,7 @@
     {
         local $SIG{__WARN__} = sub {};
         eval { $dbh->do("DROP TABLE cd") };
-        $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(255) NOT NULL UNIQUE, year VARCHAR(255));");
+        $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER);");
     }
 
     $schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 });

Modified: DBIx-Class/0.08/branches/view_support/t/51threadtxn.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/51threadtxn.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/51threadtxn.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -44,7 +44,7 @@
     {
         local $SIG{__WARN__} = sub {};
         eval { $dbh->do("DROP TABLE cd") };
-        $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(255) NOT NULL UNIQUE, year VARCHAR(255));");
+        $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER);");
     }
 
     $schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 });

Modified: DBIx-Class/0.08/branches/view_support/t/60core.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/60core.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/60core.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -153,7 +153,7 @@
 my $cd = $schema->resultset("CD")->find(1);
 my %cols = $cd->get_columns;
 
-cmp_ok(keys %cols, '==', 4, 'get_columns number of columns ok');
+cmp_ok(keys %cols, '==', 5, 'get_columns number of columns ok');
 
 is($cols{title}, 'Spoonful of bees', 'get_columns values ok');
 
@@ -169,7 +169,7 @@
 # check whether ResultSource->columns returns columns in order originally supplied
 my @cd = $schema->source("CD")->columns;
 
-is_deeply( \@cd, [qw/cdid artist title year/], 'column order');
+is_deeply( \@cd, [qw/cdid artist title year genreid/], 'column order');
 
 $cd = $schema->resultset("CD")->search({ title => 'Spoonful of bees' }, { columns => ['title'] })->next;
 is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly');
@@ -335,9 +335,9 @@
 
 # test remove_columns
 {
-  is_deeply([$schema->source('CD')->columns], [qw/cdid artist title year/]);
+  is_deeply([$schema->source('CD')->columns], [qw/cdid artist title year genreid/]);
   $schema->source('CD')->remove_columns('year');
-  is_deeply([$schema->source('CD')->columns], [qw/cdid artist title/]);
+  is_deeply([$schema->source('CD')->columns], [qw/cdid artist title genreid/]);
   ok(! exists $schema->source('CD')->_columns->{'year'}, 'year still exists in _columns');
 }
 

Modified: DBIx-Class/0.08/branches/view_support/t/66relationship.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/66relationship.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/66relationship.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -212,7 +212,7 @@
 
 my $undef_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007 });
 is($undef_artist_cd->has_column_loaded('artist'), '', 'FK not loaded');
-is($undef_artist_cd->search_related('artist')->count, 3, 'open search on undef FK');
+is($undef_artist_cd->search_related('artist')->count, 0, '0=1 search when FK does not exist and object not yet in db');
 
 my $def_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007, artist => undef });
 is($def_artist_cd->has_column_loaded('artist'), 1, 'FK loaded');

Modified: DBIx-Class/0.08/branches/view_support/t/73oracle_inflate.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/73oracle_inflate.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/73oracle_inflate.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -7,16 +7,18 @@
 
 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
 
-eval "use DateTime; use DateTime::Format::Oracle;";
-if ($@) {
-    plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing';
-}
-elsif (not ($dsn && $user && $pass)) {
+if (not ($dsn && $user && $pass)) {
     plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
          'Warning: This test drops and creates a table called \'track\'';
 }
 else {
-    plan tests => 4;
+    eval "use DateTime; use DateTime::Format::Oracle;";
+    if ($@) {
+        plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing';
+    }
+    else {
+        plan tests => 4;
+    }
 }
 
 # DateTime::Format::Oracle needs this set

Modified: DBIx-Class/0.08/branches/view_support/t/74mssql.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/74mssql.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/74mssql.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -26,10 +26,11 @@
 
 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
     DROP TABLE artist");
+$dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL
+    DROP TABLE cd");
 
 $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255));");
-$dbh->do("CREATE TABLE cd (cdid INT IDENTITY PRIMARY KEY, artist INT,  title VARCHAR(100), year VARCHAR(100));");
-
+$dbh->do("CREATE TABLE cd (cdid INT IDENTITY PRIMARY KEY, artist INT,  title VARCHAR(100), year VARCHAR(100), genreid INT NULL);");
 # Just to test compat shim, Auto is in Core
 $schema->class('Artist')->load_components('PK::Auto::MSSQL');
 

Modified: DBIx-Class/0.08/branches/view_support/t/77prefetch.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/77prefetch.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/77prefetch.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -69,7 +69,7 @@
 # test for partial prefetch via columns attr
 my $cd = $schema->resultset('CD')->find(1,
     {
-      columns => [qw/title artist.name/], 
+      columns => [qw/title artist artist.name/], 
       join => { 'artist' => {} }
     }
 );

Modified: DBIx-Class/0.08/branches/view_support/t/91debug.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/91debug.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/91debug.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -55,7 +55,7 @@
     my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
     like(
         $sql,
-        qr/\QSELECT me.cdid, me.artist, me.title, me.year FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? ): '1', '1', '3'\E/,
+        qr/\QSELECT me.cdid, me.artist, me.title, me.year, me.genreid FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? ): '1', '1', '3'\E/,
         'got correct SQL with all bind parameters'
     );
 }

Modified: DBIx-Class/0.08/branches/view_support/t/93single_accessor_object.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/93single_accessor_object.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/93single_accessor_object.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -2,12 +2,13 @@
 use warnings;  
 
 use Test::More;
+use Test::Exception;
 use lib qw(t/lib);
 use DBICTest;
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 7;
+plan tests => 10;
 
 # Test various uses of passing an object to find, create, and update on a single
 # rel accessor
@@ -40,3 +41,24 @@
   $track->update({ disc => $another_cd });
   is($track->get_column('cd'), $another_cd->cdid, 'track matches another CD after update');
 }
+
+$schema = DBICTest->init_schema();
+
+{
+	my $artist = $schema->resultset('Artist')->create({ artistid => 666, name => 'bad religion' });
+	my $cd = $schema->resultset('CD')->create({ cdid => 187, artist => 1, title => 'how could hell be any worse?', year => 1982, genreid => undef });
+
+	ok(!defined($cd->genreid), 'genreid is NULL');
+	ok(!defined($cd->genre), 'genre accessor returns undef');
+}
+
+$schema = DBICTest->init_schema();
+
+{
+	my $artist = $schema->resultset('Artist')->create({ artistid => 666, name => 'bad religion' });
+	my $genre = $schema->resultset('Genre')->create({ name => 'disco' });
+	my $cd = $schema->resultset('CD')->create({ cdid => 187, artist => 1, title => 'how could hell be any worse?', year => 1982 });
+
+	dies_ok { $cd->genre } 'genre accessor throws without column';
+}
+

Modified: DBIx-Class/0.08/branches/view_support/t/96file_column.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/96file_column.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/96file_column.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -10,7 +10,7 @@
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 9;
+plan tests => 11;
 
 my $rs = $schema->resultset('FileColumn');
 my $fname = '96file_column.t';
@@ -65,3 +65,23 @@
 $fc->delete;
 
 ok ( ! -e $storage, 'storage deleted' );
+
+TODO: {
+    local $TODO = 'need resultset delete override to delete_all';
+
+    $fh = $source_file->openr or die "failed to open $source_file: $!\n";
+    $fc = $rs->create({ file => { handle => $fh, filename => $fname } });
+
+    # read it back
+    $fc->discard_changes;
+
+    $storage = file(
+        $fc->column_info('file')->{file_column_path},
+        $fc->id,
+        $fc->file->{filename},
+    );
+    ok ( -e $storage, 'storage exists (2)' );
+
+    $rs->delete;
+    ok ( ! -e $storage, 'storage does not exist after $rs->delete' );
+};

Modified: DBIx-Class/0.08/branches/view_support/t/96multi_create.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/96multi_create.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/96multi_create.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -51,16 +51,16 @@
 
 is($newartist2->name, 'Fred 3', 'Created new artist with cds via find_or_create');
 
-my $artist2 = $schema->resultset('Artist')->create({ artistid => 1000,
+my $artist2 = $schema->resultset('Artist')->create({
                                                     name => 'Fred 3',
                                                      cds => [
-                                                             { artist => 1000,
+                                                             {
                                                                title => 'Music to code by',
                                                                year => 2007,
                                                              },
                                                              ],
                                                     cds_unordered => [
-                                                             { artist => 1000,
+                                                             {
                                                                title => 'Music to code by',
                                                                year => 2007,
                                                              },
@@ -202,7 +202,7 @@
 eval {
 	$schema->resultset("CD")->create({ 
               cdid => 28, 
-               title => 'Boogie Wiggle', 
+              title => 'Boogie Wiggle', 
               year => '2007', 
               artist => { artistid => 18, name => 'larry' }
              });
@@ -211,9 +211,9 @@
 
 # Make sure exceptions from errors in created rels propogate
 eval {
-    my $t = $schema->resultset("Track")->new({});
-    $t->cd($t->new_related('cd', { artist => undef } ) );
-    $t->{_rel_in_storage} = 0;
+    my $t = $schema->resultset("Track")->new({ cd => { artist => undef } });
+    #$t->cd($t->new_related('cd', { artist => undef } ) );
+    #$t->{_rel_in_storage} = 0;
     $t->insert;
 };
 like($@, qr/cd.artist may not be NULL/, "Exception propogated properly");

Modified: DBIx-Class/0.08/branches/view_support/t/cdbi-DeepAbstractSearch/01_search.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/cdbi-DeepAbstractSearch/01_search.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/cdbi-DeepAbstractSearch/01_search.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -2,6 +2,12 @@
 use Test::More;
 
 BEGIN {
+    eval "use DBIx::Class::CDBICompat;";
+    if ($@) {
+        plan (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@");
+        next;
+    }
+
     plan skip_all => 'needs DBD::SQLite for testing'
         unless eval { require DBD::SQLite };
     

Modified: DBIx-Class/0.08/branches/view_support/t/cdbi-t/15-accessor.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/cdbi-t/15-accessor.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/cdbi-t/15-accessor.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -4,7 +4,6 @@
 BEGIN {
   eval "use DBIx::Class::CDBICompat;";
   if ($@) {
-      diag $@;
     plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required');
     next;
   }

Modified: DBIx-Class/0.08/branches/view_support/t/cdbi-t/22-deflate_order.t
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/cdbi-t/22-deflate_order.t	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/cdbi-t/22-deflate_order.t	2008-09-16 11:38:37 UTC (rev 4808)
@@ -3,6 +3,12 @@
 
 use Test::More;
 
+eval "use DBIx::Class::CDBICompat;";
+if ($@) {
+    plan (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@");
+    next;
+}
+
 eval { require Time::Piece::MySQL };
 plan skip_all => "Need Time::Piece::MySQL for this test" if $@;
 

Modified: DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema/CD.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema/CD.pm	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema/CD.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -20,6 +20,10 @@
     data_type => 'varchar',
     size      => 100,
   },
+  'genreid' => { 
+    data_type => 'integer',
+    is_nullable => 1,
+  }
 );
 __PACKAGE__->set_primary_key('cdid');
 __PACKAGE__->add_unique_constraint([ qw/artist title/ ]);
@@ -49,4 +53,11 @@
     { order_by => 'producer.name' },
 );
 
+__PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre', { 'foreign.genreid' => 'self.genreid' });
+
+#__PACKAGE__->add_relationship('genre', 'DBICTest::Schema::Genre',
+#    { 'foreign.genreid' => 'self.genreid' },
+#    { 'accessor' => 'single' }
+#);
+
 1;

Added: DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema/Genre.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema/Genre.pm	                        (rev 0)
+++ DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema/Genre.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -0,0 +1,22 @@
+package DBICTest::Schema::Genre;
+
+use strict;
+
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table('genre');
+__PACKAGE__->add_columns(qw/genreid name/);
+__PACKAGE__->set_primary_key('genreid');
+
+1;
+package DBICTest::Schema::Genre;
+
+use strict;
+
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table('genre');
+__PACKAGE__->add_columns(qw/genreid name/);
+__PACKAGE__->set_primary_key('genreid');
+
+1;

Modified: DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema.pm
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema.pm	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/lib/DBICTest/Schema.pm	2008-09-16 11:38:37 UTC (rev 4808)
@@ -11,6 +11,7 @@
   Employee
   CD
   FileColumn
+  Genre
   Link
   Bookmark
   #dummy

Modified: DBIx-Class/0.08/branches/view_support/t/lib/sqlite.sql
===================================================================
--- DBIx-Class/0.08/branches/view_support/t/lib/sqlite.sql	2008-09-15 19:49:18 UTC (rev 4807)
+++ DBIx-Class/0.08/branches/view_support/t/lib/sqlite.sql	2008-09-16 11:38:37 UTC (rev 4808)
@@ -90,10 +90,19 @@
   cdid INTEGER PRIMARY KEY NOT NULL,
   artist integer NOT NULL,
   title varchar(100) NOT NULL,
-  year varchar(100) NOT NULL
+  year varchar(100) NOT NULL,
+  genreid integer
 );
 
 --
+-- Table: genre
+--
+CREATE TABLE genre (
+  genreid INTEGER PRIMARY KEY NOT NULL,
+  name varchar(100) NOT NULL
+);
+
+--
 -- Table: bookmark
 --
 CREATE TABLE bookmark (




More information about the Bast-commits mailing list