[Bast-commits] r6779 - in DBIx-Class/0.08/branches/sybase: . lib/DBIx/Class lib/DBIx/Class/Storage lib/DBIx/Class/Storage/DBI t t/count t/inflate t/lib/DBICTest/Schema t/multi_create t/prefetch t/relationship

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Wed Jun 24 05:43:55 GMT 2009


Author: caelum
Date: 2009-06-24 05:43:53 +0000 (Wed, 24 Jun 2009)
New Revision: 6779

Added:
   DBIx-Class/0.08/branches/sybase/t/count/count_rs.t
   DBIx-Class/0.08/branches/sybase/t/multi_create/in_memory.t
   DBIx-Class/0.08/branches/sybase/t/multi_create/standard.t
   DBIx-Class/0.08/branches/sybase/t/multi_create/torture.t
Removed:
   DBIx-Class/0.08/branches/sybase/t/96multi_create.t
   DBIx-Class/0.08/branches/sybase/t/96multi_create_new.t
   DBIx-Class/0.08/branches/sybase/t/96multi_create_torture.t
Modified:
   DBIx-Class/0.08/branches/sybase/
   DBIx-Class/0.08/branches/sybase/Changes
   DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/ResultSet.pm
   DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Row.pm
   DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Schema.pm
   DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/mysql.pm
   DBIx-Class/0.08/branches/sybase/t/count/distinct.t
   DBIx-Class/0.08/branches/sybase/t/inflate/serialize.t
   DBIx-Class/0.08/branches/sybase/t/lib/DBICTest/Schema/Track.pm
   DBIx-Class/0.08/branches/sybase/t/prefetch/with_limit.t
   DBIx-Class/0.08/branches/sybase/t/relationship/core.t
   DBIx-Class/0.08/branches/sybase/t/zzzzzzz_perl_perf_bug.t
Log:
 r5588 at hlagh (orig r6733):  ribasushi | 2009-06-20 01:16:02 -0700
 todoify skip
 r5590 at hlagh (orig r6735):  ribasushi | 2009-06-20 03:37:52 -0700
 Clarify test
 r5594 at hlagh (orig r6739):  ribasushi | 2009-06-20 06:22:06 -0700
 Disambiguate populate() return
 r5603 at hlagh (orig r6742):  ribasushi | 2009-06-20 14:30:23 -0700
  r6737 at Thesaurus (orig r6736):  ribasushi | 2009-06-20 12:39:34 +0200
  new branch to streamline count() and introduce count_rs()
  r6738 at Thesaurus (orig r6737):  ribasushi | 2009-06-20 12:44:09 +0200
  Add count_rs, move the code back from DBI - leave only sql specific hooks
  r6739 at Thesaurus (orig r6738):  ribasushi | 2009-06-20 12:54:11 +0200
  Test count_rs
  r6742 at Thesaurus (orig r6741):  ribasushi | 2009-06-20 23:30:10 +0200
  More tests and a really working count_rs
 
 r5613 at hlagh (orig r6752):  ribasushi | 2009-06-21 00:00:21 -0700
 Clenaup text
 r5614 at hlagh (orig r6753):  ribasushi | 2009-06-21 05:37:56 -0700
 make_column_dirty fix
 r5617 at hlagh (orig r6755):  ribasushi | 2009-06-21 14:12:40 -0700
 Fix borked test
 r5619 at hlagh (orig r6763):  ribasushi | 2009-06-23 01:33:59 -0700
 Real inheritance ordering for load_namespaces
 r5623 at hlagh (orig r6771):  ribasushi | 2009-06-23 07:46:18 -0700
 Move tests around, add extra has_one relationship
 r5624 at hlagh (orig r6772):  caelum | 2009-06-23 09:36:22 -0700
 add missing ' to doc



Property changes on: DBIx-Class/0.08/branches/sybase
___________________________________________________________________
Name: svk:merge
   - 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/resultsetcolumn_custom_columns:5160
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/sqla_1.50_compat:5414
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/trunk:5969
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
ab17426e-7cd3-4704-a2a2-80b7c0a611bb:/local/dbic_column_attr:10946
ab17426e-7cd3-4704-a2a2-80b7c0a611bb:/local/dbic_trunk:11142
bd5ac9a7-f185-4d95-9186-dbb8b392a572:/local/os/bast/DBIx-Class/0.08/trunk:2798
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/belongs_to_null_col_fix:5244
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/column_attr:5074
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/count_distinct:6218
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/diamond_relationships:6310
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/fix-update-and-delete-as_query:6162
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/joined_count:6323
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/multi_stuff:5565
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/mystery_join:6589
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-tweaks:6222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/order_by_refactor:6475
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/prefetch:5699
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/prefetch_limit:6724
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/rsrc_in_storage:6577
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/rt_bug_41083:5437
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/sqla_1.50_compat:5321
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-tweaks:6262
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/subclassed_rsset:5930
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/subquery:5617
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/sybase_mssql:6125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/top_limit_altfix:6429
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/type_aware_update:6619
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/branches/views:5585
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:6725
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
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/resultsetcolumn_custom_columns:5160
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/sqla_1.50_compat:5414
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/trunk:5969
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
ab17426e-7cd3-4704-a2a2-80b7c0a611bb:/local/dbic_column_attr:10946
ab17426e-7cd3-4704-a2a2-80b7c0a611bb:/local/dbic_trunk:11142
bd5ac9a7-f185-4d95-9186-dbb8b392a572:/local/os/bast/DBIx-Class/0.08/trunk:2798
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/belongs_to_null_col_fix:5244
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/column_attr:5074
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/count_distinct:6218
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/count_rs:6741
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/diamond_relationships:6310
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/fix-update-and-delete-as_query:6162
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/joined_count:6323
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/multi_stuff:5565
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/mystery_join:6589
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-tweaks:6222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/order_by_refactor:6475
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/prefetch:5699
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/prefetch_limit:6724
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/rsrc_in_storage:6577
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/rt_bug_41083:5437
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/sqla_1.50_compat:5321
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-tweaks:6262
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/subclassed_rsset:5930
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/subquery:5617
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/sybase_mssql:6125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/top_limit_altfix:6429
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/type_aware_update:6619
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/branches/views:5585
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:6772
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/sybase/Changes
===================================================================
--- DBIx-Class/0.08/branches/sybase/Changes	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/Changes	2009-06-24 05:43:53 UTC (rev 6779)
@@ -5,6 +5,10 @@
         - Fixed HRI returning too many empty results on multilevel
           nonexisting prefetch
         - Fixed the prefetch with limit bug
+        - New resultsed method count_rs, returns a ::ResultSetColumn
+          which in turn returns a single count value
+        - make_column_dirty() now overwrites the deflated value with an
+          inflated one if such exists
 
 0.08107 2009-06-14 08:21:00 (UTC)
         - Fix serialization regression introduced in 0.08103 (affects

Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/ResultSet.pm	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/ResultSet.pm	2009-06-24 05:43:53 UTC (rev 6779)
@@ -1154,17 +1154,122 @@
   return $self->search(@_)->count if @_ and defined $_[0];
   return scalar @{ $self->get_cache } if $self->get_cache;
 
-  my $meth = $self->_has_resolved_attr (qw/collapse group_by/)
-    ? 'count_grouped'
-    : 'count'
-  ;
+  my $attrs = $self->_resolved_attrs_copy;
 
-  my $attrs = $self->_resolved_attrs_copy;
+  # this is a little optimization - it is faster to do the limit
+  # adjustments in software, instead of a subquery
+  my $rows = delete $attrs->{rows};
+  my $offset = delete $attrs->{offset};
+
+  my $crs;
+  if ($self->_has_resolved_attr (qw/collapse group_by/)) {
+    $crs = $self->_count_subq_rs ($attrs);
+  }
+  else {
+    $crs = $self->_count_rs ($attrs);
+  }
+  my $count = $crs->next;
+
+  $count -= $offset if $offset;
+  $count = $rows if $rows and $rows < $count;
+  $count = 0 if ($count < 0);
+
+  return $count;
+}
+
+=head2 count_rs
+
+=over 4
+
+=item Arguments: $cond, \%attrs??
+
+=item Return Value: $count_rs
+
+=back
+
+Same as L</count> but returns a L<DBIx::Class::ResultSetColumn> object.
+This can be very handy for subqueries:
+
+  ->search( { amount => $some_rs->count_rs->as_query } )
+
+As with regular resultsets the SQL query will be executed only after
+the resultset is accessed via L</next> or L</all>. That would return
+the same single value obtainable via L</count>.
+
+=cut
+
+sub count_rs {
+  my $self = shift;
+  return $self->search(@_)->count_rs if @_;
+
+  # this may look like a lack of abstraction (count() does about the same)
+  # but in fact an _rs *must* use a subquery for the limits, as the
+  # software based limiting can not be ported if this $rs is to be used
+  # in a subquery itself (i.e. ->as_query)
+  if ($self->_has_resolved_attr (qw/collapse group_by offset rows/)) {
+    return $self->_count_subq_rs;
+  }
+  else {
+    return $self->_count_rs;
+  }
+}
+
+#
+# returns a ResultSetColumn object tied to the count query
+#
+sub _count_rs {
+  my ($self, $attrs) = @_;
+
   my $rsrc = $self->result_source;
+  $attrs ||= $self->_resolved_attrs;
 
-  return $rsrc->storage->$meth ($rsrc, $attrs);
+  my $tmp_attrs = { %$attrs };
+
+  # take off any limits, record_filter is cdbi, and no point of ordering a count 
+  delete $tmp_attrs->{$_} for (qw/select as rows offset order_by record_filter/);
+
+  # overwrite the selector (supplied by the storage)
+  $tmp_attrs->{select} = $rsrc->storage->_count_select ($rsrc, $tmp_attrs);
+  $tmp_attrs->{as} = 'count';
+
+  my $tmp_rs = $rsrc->resultset_class->new($rsrc, $tmp_attrs)->get_column ('count');
+
+  return $tmp_rs;
 }
 
+#
+# same as above but uses a subquery
+#
+sub _count_subq_rs {
+  my ($self, $attrs) = @_;
+
+  my $rsrc = $self->result_source;
+  $attrs ||= $self->_resolved_attrs_copy;
+
+  my $sub_attrs = { %$attrs };
+
+  # these can not go in the subquery, and there is no point of ordering it
+  delete $sub_attrs->{$_} for qw/collapse select as order_by/;
+
+  # if we prefetch, we group_by primary keys only as this is what we would get out of the rs via ->next/->all
+  # clobber old group_by regardless
+  if ( keys %{$attrs->{collapse}} ) {
+    $sub_attrs->{group_by} = [ map { "$attrs->{alias}.$_" } ($rsrc->primary_columns) ]
+  }
+
+  $sub_attrs->{select} = $rsrc->storage->_subq_count_select ($rsrc, $sub_attrs);
+
+  $attrs->{from} = [{
+    count_subq => $rsrc->resultset_class->new ($rsrc, $sub_attrs )->as_query
+  }];
+
+  # the subquery replaces this
+  delete $attrs->{$_} for qw/where bind collapse group_by having having_bind rows offset/;
+
+  return $self->_count_rs ($attrs);
+}
+
+
 sub _bool {
   return 1;
 }
@@ -1514,8 +1619,9 @@
 to insert the data, as this is a faster method.
 
 Otherwise, each set of data is inserted into the database using
-L<DBIx::Class::ResultSet/create>, and a arrayref of the resulting row
-objects is returned.
+L<DBIx::Class::ResultSet/create>, and the resulting objects are
+accumulated into an array. The array itself, or an array reference
+is returned depending on scalar or list context.
 
 Example:  Assuming an Artist Class that has many CDs Classes relating:
 
@@ -1581,7 +1687,7 @@
     foreach my $item (@$data) {
       push(@created, $self->create($item));
     }
-    return @created;
+    return wantarray ? @created : \@created;
   } else {
     my ($first, @rest) = @$data;
 
@@ -2080,7 +2186,7 @@
 =back
 
   $cd->cd_to_producer->find_or_create({ producer => $producer },
-                                      { key => 'primary });
+                                      { key => 'primary' });
 
 Tries to find a record based on its primary key or unique constraints; if none
 is found, creates one and returns that instead.
@@ -2571,22 +2677,24 @@
     $self->{attrs}{alias} => $source->from,
   } ];
 
-  if ( exists $attrs->{join} || exists $attrs->{prefetch} ) {
+  if ( $attrs->{join} || $attrs->{prefetch} ) {
+
+    $self->throw_exception ('join/prefetch can not be used with a literal scalarref {from}')
+      if ref $attrs->{from} ne 'ARRAY';
+
     my $join = delete $attrs->{join} || {};
 
     if ( defined $attrs->{prefetch} ) {
       $join = $self->_merge_attr( $join, $attrs->{prefetch} );
-
     }
 
     $attrs->{from} =    # have to copy here to avoid corrupting the original
       [
-      @{ $attrs->{from} },
-      $source->_resolve_join(
-        $join, $alias, { %{ $attrs->{seen_join} || {} } }
-      )
+        @{ $attrs->{from} },
+        $source->_resolve_join(
+          $join, $alias, { %{ $attrs->{seen_join} || {} } }
+        )
       ];
-
   }
 
   if ( $attrs->{order_by} ) {

Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Row.pm	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Row.pm	2009-06-24 05:43:53 UTC (rev 6779)
@@ -710,7 +710,21 @@
 
   $self->throw_exception( "No such column '${column}'" )
     unless exists $self->{_column_data}{$column} || $self->has_column($column);
+
+  # the entire clean/dirty code relieas on exists, not on true/false
+  return 1 if exists $self->{_dirty_columns}{$column};
+
   $self->{_dirty_columns}{$column} = 1;
+
+  # if we are just now making the column dirty, and if there is an inflated
+  # value, force it over the deflated one
+  if (exists $self->{_inflated_column}{$column}) {
+    $self->store_column($column,
+      $self->_deflated_column(
+        $column, $self->{_inflated_column}{$column}
+      )
+    );
+  }
 }
 
 =head2 get_inflated_columns

Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Schema.pm	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Schema.pm	2009-06-24 05:43:53 UTC (rev 6779)
@@ -7,6 +7,7 @@
 use Carp::Clan qw/^DBIx::Class/;
 use Scalar::Util qw/weaken/;
 use File::Spec;
+use MRO::Compat;
 use Sub::Name ();
 require Module::Find;
 
@@ -239,16 +240,29 @@
     local *Class::C3::reinitialize = sub { };
     use warnings 'redefine';
 
-    # ensure classes are loaded and fetch properly sorted classes
+    # ensure classes are loaded and attached in inheritance order
     $class->ensure_class_loaded($_) foreach(values %results);
-    my @subclass_last = sort { $results{$a}->isa($results{$b}) } keys(%results);
-    
+    my %inh_idx;
+    my @subclass_last = sort {
+
+      ($inh_idx{$a} ||=
+        scalar @{mro::get_linear_isa( $results{$a} )}
+      )
+
+          <=>
+
+      ($inh_idx{$b} ||=
+        scalar @{mro::get_linear_isa( $results{$b} )}
+      )
+
+    } keys(%results);
+
     foreach my $result (@subclass_last) {
       my $result_class = $results{$result};
 
       my $rs_class = delete $resultsets{$result};
       my $rs_set = $class->_ns_get_rsrc_instance ($result_class)->resultset_class;
-      
+
       if($rs_set && $rs_set ne 'DBIx::Class::ResultSet') {
         if($rs_class && $rs_class ne $rs_set) {
           carp "We found ResultSet class '$rs_class' for '$result', but it seems "

Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/mysql.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/mysql.pm	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/mysql.pm	2009-06-24 05:43:53 UTC (rev 6779)
@@ -64,10 +64,10 @@
 # primary keys of the main table in the inner query. This hopefully still
 # hits the indexes and keeps mysql happy.
 # (mysql does not care if the SELECT and the GROUP BY match)
-sub _grouped_count_select {
-  my ($self, $source, $rs_args) = @_;
-  my @pcols = map { join '.', $rs_args->{alias}, $_ } ($source->primary_columns);
-  return @pcols ? \@pcols : $rs_args->{group_by};
+sub _subq_count_select {
+  my ($self, $source, $rs_attrs) = @_;
+  my @pcols = map { join '.', $rs_attrs->{alias}, $_ } ($source->primary_columns);
+  return @pcols ? \@pcols : [ 1 ];
 }
 
 1;

Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm	2009-06-24 05:43:53 UTC (rev 6779)
@@ -1312,6 +1312,7 @@
   $self->throw_exception ('Prefetch with limit (rows/offset) is not supported on resultsets with a custom from attribute')
     if (ref $from ne 'ARRAY');
 
+
   # separate attributes
   my $sub_attrs = { %$attrs };
   delete $attrs->{$_} for qw/where bind rows offset/;
@@ -1330,14 +1331,32 @@
     ];
   }
 
+  # mangle {from}
+  $from = [ @$from ];
+  my $select_root = shift @$from;
+  my @outer_from = @$from;
 
-  # mangle the head of the {from}
-  my $self_ident = shift @$from;
-
+  my %inner_joins;
   my %join_info = map { $_->[0]{-alias} => $_->[0] } (@$from);
 
-  my (%inner_joins);
+  # in complex search_related chains $alias may *not* be 'me'
+  # so always include it in the inner join, and also shift away
+  # from the outer stack, so that the two datasets actually do
+  # meet
+  if ($select_root->{-alias} ne $alias) {
+    $inner_joins{$alias} = 1;
 
+    while (@outer_from && $outer_from[0][0]{-alias} ne $alias) {
+      shift @outer_from;
+    }
+    if (! @outer_from) {
+      $self->throw_exception ("Unable to find '$alias' in the {from} stack, something is wrong");
+    }
+
+    shift @outer_from; # the new subquery will represent this alias, so get rid of it
+  }
+
+
   # decide which parts of the join will remain on the inside
   #
   # this is not a very viable optimisation, but it was written
@@ -1395,22 +1414,21 @@
   }
 
   # construct the inner $from for the subquery
-  my $inner_from = [ $self_ident ];
-  if (keys %inner_joins) {
-    for my $j (@$from) {
-      push @$inner_from, $j if $inner_joins{$j->[0]{-alias}};
-    }
+  my $inner_from = [ $select_root ];
+  for my $j (@$from) {
+    push @$inner_from, $j if $inner_joins{$j->[0]{-alias}};
+  }
 
-    # if a multi-type join was needed in the subquery ("multi" is indicated by
-    # presence in {collapse}) - add a group_by to simulate the collapse in the subq
-    for my $alias (keys %inner_joins) {
+  # if a multi-type join was needed in the subquery ("multi" is indicated by
+  # presence in {collapse}) - add a group_by to simulate the collapse in the subq
 
-      # the dot comes from some weirdness in collapse
-      # remove after the rewrite
-      if ($attrs->{collapse}{".$alias"}) {
-        $sub_attrs->{group_by} = $sub_select;
-        last;
-      }
+  for my $alias (keys %inner_joins) {
+
+    # the dot comes from some weirdness in collapse
+    # remove after the rewrite
+    if ($attrs->{collapse}{".$alias"}) {
+      $sub_attrs->{group_by} = $sub_select;
+      last;
     }
   }
 
@@ -1422,14 +1440,14 @@
     $sub_attrs
   );
 
-  # put it back in $from
-  unshift @$from, { $alias => $subq };
+  # put it in the new {from}
+  unshift @outer_from, { $alias => $subq };
 
   # This is totally horrific - the $where ends up in both the inner and outer query
   # Unfortunately not much can be done until SQLA2 introspection arrives
   #
   # OTOH it can be seen as a plus: <ash> (notes that this query would make a DBA cry ;)
-  return ($from, $select, $where, $attrs);
+  return (\@outer_from, $select, $where, $attrs);
 }
 
 sub _resolve_ident_sources {
@@ -1462,82 +1480,37 @@
   return $alias2source;
 }
 
-sub _copy_attributes_for_count {
-  my ($self, $source, $attrs) = @_;
-  my %attrs = %$attrs;
-
-  # take off any column specs, any pagers, record_filter is cdbi, and no point of ordering a count
-  delete @attrs{qw/select as rows offset page order_by record_filter/};
-
-  return \%attrs;
+# Returns a counting SELECT for a simple count
+# query. Abstracted so that a storage could override
+# this to { count => 'firstcol' } or whatever makes
+# sense as a performance optimization
+sub _count_select {
+  #my ($self, $source, $rs_attrs) = @_;
+  return { count => '*' };
 }
 
-sub count {
-  my ($self, $source, $attrs) = @_;
-
-  my $tmp_attrs = $self->_copy_attributes_for_count($source, $attrs);
-
-  # overwrite the selector
-  $tmp_attrs->{select} = { count => '*' };
-
-  my $tmp_rs = $source->resultset_class->new($source, $tmp_attrs);
-  my ($count) = $tmp_rs->cursor->next;
-
-  # if the offset/rows attributes are still present, we did not use
-  # a subquery, so we need to make the calculations in software
-  $count -= $attrs->{offset} if $attrs->{offset};
-  $count = $attrs->{rows} if $attrs->{rows} and $attrs->{rows} < $count;
-  $count = 0 if ($count < 0);
-
-  return $count;
-}
-
-sub count_grouped {
-  my ($self, $source, $attrs) = @_;
-
-  # copy for the subquery, we need to do some adjustments to it too
-  my $sub_attrs = { %$attrs };
-
-  # these can not go in the subquery, and there is no point of ordering it
-  delete $sub_attrs->{$_} for qw/collapse select as order_by/;
-
-  # if we prefetch, we group_by primary keys only as this is what we would get out of the rs via ->next/->all
-  # simply deleting group_by suffices, as the code below will re-fill it
-  # Note: we check $attrs, as $sub_attrs has collapse deleted
-  if (ref $attrs->{collapse} and keys %{$attrs->{collapse}} ) {
-    delete $sub_attrs->{group_by};
-  }
-
-  $sub_attrs->{group_by} ||= [ map { "$attrs->{alias}.$_" } ($source->primary_columns) ];
-  $sub_attrs->{select} = $self->_grouped_count_select ($source, $sub_attrs);
-
-  $attrs->{from} = [{
-    count_subq => $source->resultset_class->new ($source, $sub_attrs )->as_query
-  }];
-
-  # the subquery replaces this
-  delete $attrs->{$_} for qw/where bind collapse group_by having having_bind rows offset/;
-
-  return $self->count ($source, $attrs);
-}
-
+# Returns a SELECT which will end up in the subselect
+# There may or may not be a group_by, as the subquery
+# might have been called to accomodate a limit
 #
-# Returns a SELECT to go with a supplied GROUP BY
-# (caled by count_grouped so a group_by is present)
-# Most databases expect them to match, but some
-# choke in various ways.
+# Most databases would be happy with whatever ends up
+# here, but some choke in various ways.
 #
-sub _grouped_count_select {
-  my ($self, $source, $rs_args) = @_;
-  return $rs_args->{group_by};
+sub _subq_count_select {
+  my ($self, $source, $rs_attrs) = @_;
+  return $rs_attrs->{group_by} if $rs_attrs->{group_by};
+
+  my @pcols = map { join '.', $rs_attrs->{alias}, $_ } ($source->primary_columns);
+  return @pcols ? \@pcols : [ 1 ];
 }
 
+
 sub source_bind_attributes {
   my ($self, $source) = @_;
-  
+
   my $bind_attributes;
   foreach my $column ($source->columns) {
-  
+
     my $data_type = $source->column_info($column)->{data_type} || '';
     $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type)
      if $data_type;

Deleted: DBIx-Class/0.08/branches/sybase/t/96multi_create.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/96multi_create.t	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/t/96multi_create.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -1,487 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use Test::Exception;
-use lib qw(t/lib);
-use DBICTest;
-
-plan tests => 93;
-
-my $schema = DBICTest->init_schema();
-
-lives_ok ( sub {
-  my $cd = $schema->resultset('CD')->create({
-    artist => { 
-      name => 'Fred Bloggs' 
-    },
-    title => 'Some CD',
-    year => 1996
-  });
-
-  isa_ok($cd, 'DBICTest::CD', 'Created CD object');
-  isa_ok($cd->artist, 'DBICTest::Artist', 'Created related Artist');
-  is($cd->artist->name, 'Fred Bloggs', 'Artist created correctly');
-}, 'simple create + parent (the stuff $rs belongs_to) ok');
-
-lives_ok ( sub {
-  my $bm_rs = $schema->resultset('Bookmark');
-  my $bookmark = $bm_rs->create({
-    link => {
-      id => 66,
-    },
-  });
-
-  isa_ok($bookmark, 'DBICTest::Bookmark', 'Created Bookrmark object');
-  isa_ok($bookmark->link, 'DBICTest::Link', 'Created related Link');
-  is (
-    $bm_rs->search (
-      { 'link.title' => $bookmark->link->title },
-      { join => 'link' },
-    )->count,
-    1,
-    'Bookmark and link made it to the DB',
-  );
-}, 'simple create where the child and parent have no values, except for an explicit parent pk ok');
-
-lives_ok ( sub {
-  my $artist = $schema->resultset('Artist')->first;
-  my $cd = $artist->create_related (cds => {
-    title => 'Music to code by',
-    year => 2007,
-    tags => [
-      { 'tag' => 'rock' },
-    ],
-  });
-
-  isa_ok($cd, 'DBICTest::CD', 'Created CD');
-  is($cd->title, 'Music to code by', 'CD created correctly');
-  is($cd->tags->count, 1, 'One tag created for CD');
-  is($cd->tags->first->tag, 'rock', 'Tag created correctly');
-
-}, 'create over > 1 levels of has_many create (A => { has_many => { B => has_many => C } } )');
-
-throws_ok (
-  sub {
-    # Create via update - add a new CD <--- THIS SHOULD HAVE NEVER WORKED!
-    $schema->resultset('Artist')->first->update({
-      cds => [
-        { title => 'Yet another CD',
-          year => 2006,
-        },
-      ],
-    });
-  },
-  qr/Recursive update is not supported over relationships of type multi/,
-  'create via update of multi relationships throws an exception'
-);
-
-lives_ok ( sub {
-  my $artist = $schema->resultset('Artist')->first;
-  my $c2p = $schema->resultset('CD_to_Producer')->create ({
-    cd => {
-      artist => $artist,
-      title => 'Bad investment',
-      year => 2008,
-      tracks => [
-        { title => 'Just buy' },
-        { title => 'Why did we do it' },
-        { title => 'Burn baby burn' },
-      ],
-    },
-    producer => {
-      name => 'Lehman Bros.',
-    },
-  });
-
-  isa_ok ($c2p, 'DBICTest::CD_to_Producer', 'Linker object created');
-  my $prod = $schema->resultset ('Producer')->find ({ name => 'Lehman Bros.' });
-  isa_ok ($prod, 'DBICTest::Producer', 'Producer row found');
-  is ($prod->cds->count, 1, 'Producer has one production');
-  my $cd = $prod->cds->first;
-  is ($cd->title, 'Bad investment', 'CD created correctly');
-  is ($cd->tracks->count, 3, 'CD has 3 tracks');
-}, 'Create m2m while originating in the linker table');
-
-
-#CD -> has_many -> Tracks -> might have -> Single -> has_many -> Tracks
-#                                               \
-#                                                \-> has_many \
-#                                                              --> CD2Producer
-#                                                /-> has_many /
-#                                               /
-#                                          Producer
-lives_ok ( sub {
-  my $artist = $schema->resultset('Artist')->first;
-  my $cd = $schema->resultset('CD')->create ({
-    artist => $artist,
-    title => 'Music to code by at night',
-    year => 2008,
-    tracks => [
-      {
-        title => 'Off by one again',
-      },
-      {
-        title => 'The dereferencer',
-        cd_single => {
-          artist => $artist,
-          year => 2008,
-          title => 'Was that a null (Single)',
-          tracks => [
-            { title => 'The dereferencer' },
-            { title => 'The dereferencer II' },
-          ],
-          cd_to_producer => [
-            {
-              producer => {
-                name => 'K&R',
-              }
-            },
-            {
-              producer => {
-                name => 'Don Knuth',
-              }
-            },
-          ]
-        },
-      },
-    ],
-  });
-
-  isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
-  is ($cd->title, 'Music to code by at night', 'Correct CD title');
-  is ($cd->tracks->count, 2, 'Two tracks on main CD');
-
-  my ($t1, $t2) = $cd->tracks->all;
-  is ($t1->title, 'Off by one again', 'Correct 1st track name');
-  is ($t1->cd_single, undef, 'No single for 1st track');
-  is ($t2->title, 'The dereferencer', 'Correct 2nd track name');
-  isa_ok ($t2->cd_single, 'DBICTest::CD', 'Created a single for 2nd track');
-
-  my $single = $t2->cd_single;
-  is ($single->tracks->count, 2, 'Two tracks on single CD');
-  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, 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',
-  );
-}, 'Create over > 1 levels of might_have with multiple has_many and multiple m2m but starting at a has_many level');
-
-#Track -> might have -> Single -> has_many -> Tracks
-#                           \
-#                            \-> has_many \
-#                                          --> CD2Producer
-#                            /-> has_many /
-#                           /
-#                       Producer
-lives_ok ( sub {
-  my $cd = $schema->resultset('CD')->first;
-  my $track = $schema->resultset('Track')->create ({
-    cd => $cd,
-    title => 'Multicreate rocks',
-    cd_single => {
-      artist => $cd->artist,
-      year => 2008,
-      title => 'Disemboweling MultiCreate',
-      tracks => [
-        { title => 'Why does mst write this way' },
-        { title => 'Chainsaw celebration' },
-        { title => 'Purl cleans up' },
-      ],
-      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',
-  );
-}, 'Create over > 1 levels of might_have with multiple has_many and multiple m2m but starting at the might_have directly');
-
-lives_ok ( sub {
-  my $artist = $schema->resultset('Artist')->first;
-  my $cd = $schema->resultset('CD')->create ({
-    artist => $artist,
-    title => 'Music to code by at twilight',
-    year => 2008,
-    artwork => {
-      images => [
-        { name => 'recursive descent' },
-        { name => 'tail packing' },
-      ],
-    },
-  });
-
-  isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
-  is ($cd->title, 'Music to code by at twilight', 'Correct CD title');
-  isa_ok ($cd->artwork, 'DBICTest::Artwork', 'Artwork created');
-
-  # this test might look weird, but it failed at one point, keep it there
-  my $art_obj = $cd->artwork;
-  ok ($art_obj->has_column_loaded ('cd_id'), 'PK/FK present on artwork object');
-  is ($art_obj->images->count, 2, 'Correct artwork image count via the new object');
-  is_deeply (
-    [ sort $art_obj->images->get_column ('name')->all ],
-    [ 'recursive descent', 'tail packing' ],
-    'Images named correctly in objects',
-  );
-
-  my $artwork = $schema->resultset('Artwork')->search (
-    { 'cd.title' => 'Music to code by at twilight' },
-    { join => 'cd' },
-  )->single;
-
-  is ($artwork->images->count, 2, 'Correct artwork image count via a new search');
-
-  is_deeply (
-    [ sort $artwork->images->get_column ('name')->all ],
-    [ 'recursive descent', 'tail packing' ],
-    'Images named correctly after search',
-  );
-}, 'Test might_have again but with a PK == FK in the middle (obviously not specified)');
-
-lives_ok ( sub {
-  my $cd = $schema->resultset('CD')->first;
-  my $track = $schema->resultset ('Track')->create ({
-    cd => $cd,
-    title => 'Black',
-    lyrics => {
-      lyric_versions => [
-        { text => 'The color black' },
-        { text => 'The colour black' },
-      ],
-    },
-  });
-
-  isa_ok ($track, 'DBICTest::Track', 'Main track object created');
-  is ($track->title, 'Black', 'Correct track title');
-  isa_ok ($track->lyrics, 'DBICTest::Lyrics', 'Lyrics created');
-
-  # this test might look weird, but it was failing at one point, keep it there
-  my $lyric_obj = $track->lyrics;
-  ok ($lyric_obj->has_column_loaded ('lyric_id'), 'PK present on lyric object');
-  ok ($lyric_obj->has_column_loaded ('track_id'), 'FK present on lyric object');
-  is ($lyric_obj->lyric_versions->count, 2, 'Correct lyric versions count via the new object');
-  is_deeply (
-    [ sort $lyric_obj->lyric_versions->get_column ('text')->all ],
-    [ 'The color black', 'The colour black' ],
-    'Lyrics text in objects matches',
-  );
-
-
-  my $lyric = $schema->resultset('Lyrics')->search (
-    { 'track.title' => 'Black' },
-    { join => 'track' },
-  )->single;
-
-  is ($lyric->lyric_versions->count, 2, 'Correct lyric versions count via a new search');
-
-  is_deeply (
-    [ sort $lyric->lyric_versions->get_column ('text')->all ],
-    [ 'The color black', 'The colour black' ],
-    'Lyrics text via search matches',
-  );
-}, 'Test might_have again but with just a PK and FK (neither specified) in the mid-table');
-
-lives_ok ( sub {
-  my $newartist2 = $schema->resultset('Artist')->find_or_create({ 
-    name => 'Fred 3',
-    cds => [
-      { 
-        title => 'Noah Act',
-        year => 2007,
-      },
-    ],
-  });
-  is($newartist2->name, 'Fred 3', 'Created new artist with cds via find_or_create');
-}, 'Nested find_or_create');
-
-lives_ok ( sub {
-  my $artist2 = $schema->resultset('Artist')->create({
-    name => 'Fred 4',
-    cds => [
-      {
-        title => 'Music to code by',
-        year => 2007,
-      },
-    ],
-    cds_unordered => [
-      {
-        title => 'Music to code by',
-        year => 2007,
-      },
-    ]
-  });
-
-  is($artist2->in_storage, 1, 'artist with duplicate rels inserted okay');
-}, 'Multiple same level has_many create');
-
-lives_ok ( sub {
-	my $artist = $schema->resultset('Artist')->first;
-	
-	my $cd_result = $artist->create_related('cds', {
-	
-		title => 'TestOneCD1',
-		year => 2007,
-		tracks => [
-			{ title => 'TrackOne' },
-			{ title => 'TrackTwo' },
-		],
-
-	});
-	
-	isa_ok( $cd_result, 'DBICTest::CD', "Got Good CD Class");
-	ok( $cd_result->title eq "TestOneCD1", "Got Expected Title");
-	
-	my $tracks = $cd_result->tracks;
-	
-	isa_ok( $tracks, 'DBIx::Class::ResultSet', 'Got Expected Tracks ResultSet');
-	
-	foreach my $track ($tracks->all)
-	{
-		isa_ok( $track, 'DBICTest::Track', 'Got Expected Track Class');
-	}
-}, 'First create_related pass');
-
-lives_ok ( sub {
-	my $artist = $schema->resultset('Artist')->first;
-	
-	my $cd_result = $artist->create_related('cds', {
-	
-		title => 'TestOneCD2',
-		year => 2007,
-		tracks => [
-			{ title => 'TrackOne' },
-			{ title => 'TrackTwo' },
-		],
-
-    liner_notes => { notes => 'I can haz liner notes?' },
-
-	});
-	
-	isa_ok( $cd_result, 'DBICTest::CD', "Got Good CD Class");
-	ok( $cd_result->title eq "TestOneCD2", "Got Expected Title");
-  ok( $cd_result->notes eq 'I can haz liner notes?', 'Liner notes');
-	
-	my $tracks = $cd_result->tracks;
-	
-	isa_ok( $tracks, 'DBIx::Class::ResultSet', "Got Expected Tracks ResultSet");
-	
-	foreach my $track ($tracks->all)
-	{
-		isa_ok( $track, 'DBICTest::Track', 'Got Expected Track Class');
-	}
-}, 'second create_related with same arguments');
-
-lives_ok ( sub {
-  my $cdp = $schema->resultset('CD_to_Producer')->create({
-    cd => { artist => 1, title => 'foo', year => 2000 },
-    producer => { name => 'jorge' }
-  });
-  ok($cdp, 'join table record created ok');
-}, 'create of parents of a record linker table');
-
-lives_ok ( sub {
-  my $kurt_cobain = { name => 'Kurt Cobain' };
-
-  my $in_utero = $schema->resultset('CD')->new({
-      title => 'In Utero',
-      year  => 1993
-    });
-
-  $kurt_cobain->{cds} = [ $in_utero ];
-
-
-  $schema->resultset('Artist')->populate([ $kurt_cobain ]); # %)
-  $a = $schema->resultset('Artist')->find({name => 'Kurt Cobain'});
-
-  is($a->name, 'Kurt Cobain', 'Artist insertion ok');
-  is($a->cds && $a->cds->first && $a->cds->first->title, 
-		  'In Utero', 'CD insertion ok');
-}, 'populate');
-
-## Create foreign key col obj including PK
-## See test 20 in 66relationships.t
-lives_ok ( sub {
-  my $new_cd_hashref = { 
-    cdid => 27, 
-    title => 'Boogie Woogie', 
-    year => '2007', 
-    artist => { artistid => 17, name => 'king luke' }
-  };
-
-  my $cd = $schema->resultset("CD")->find(1);
-
-  is($cd->artist->id, 1, 'rel okay');
-
-  my $new_cd = $schema->resultset("CD")->create($new_cd_hashref);
-  is($new_cd->artist->id, 17, 'new id retained okay');
-}, 'Create foreign key col obj including PK');
-
-lives_ok ( sub {
-	$schema->resultset("CD")->create({ 
-              cdid => 28, 
-              title => 'Boogie Wiggle', 
-              year => '2007', 
-              artist => { artistid => 18, name => 'larry' }
-             });
-}, 'new cd created without clash on related artist');
-
-throws_ok ( sub {
-    my $t = $schema->resultset("Track")->new({ cd => { artist => undef } });
-    #$t->cd($t->new_related('cd', { artist => undef } ) );
-    #$t->{_rel_in_storage} = 0;
-    $t->insert;
-}, qr/cd.artist may not be NULL/, "Exception propogated properly");
-
-lives_ok ( sub {
-  $schema->resultset('CD')->create ({
-    artist => {
-      name => 'larry', # should already exist
-    },
-    title => 'Warble Marble',
-    year => '2009',
-    cd_to_producer => [
-      { producer => { name => 'Cowboy Neal' } },
-    ],
-  });
-
-  my $m2m_cd = $schema->resultset('CD')->search ({ title => 'Warble Marble'});
-  is ($m2m_cd->count, 1, 'One CD row created via M2M create');
-  is ($m2m_cd->first->producers->count, 1, 'CD row created with one producer');
-  is ($m2m_cd->first->producers->first->name, 'Cowboy Neal', 'Correct producer row created');
-}, 'Test multi create over many_to_many');
-
-1;

Deleted: DBIx-Class/0.08/branches/sybase/t/96multi_create_new.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/96multi_create_new.t	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/t/96multi_create_new.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -1,74 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use Test::Exception;
-use lib qw(t/lib);
-use DBICTest;
-
-plan tests => 12;
-
-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_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode' });
-    my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave Slightly Noisily', 'year' => 1982});
-    eval {
-        $new_related_cd->insert;
-    };
-    is ($@, '', 'CD insertion survives by finding artist');
-    ok($new_artist->in_storage, 'artist inserted');
-    ok($new_related_cd->in_storage, 'new_related_cd inserted');
-}
-
-{
-    my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode 2: Insertion Boogaloo' });
-    my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave Loudly While Singing Off Key', 'year' => 1982});
-    eval {
-        $new_related_cd->insert;
-    };
-    is ($@, '', 'CD insertion survives by inserting artist');
-    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');
-}

Deleted: DBIx-Class/0.08/branches/sybase/t/96multi_create_torture.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/96multi_create_torture.t	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/t/96multi_create_torture.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -1,224 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use Test::Exception;
-use lib qw(t/lib);
-use DBICTest;
-
-plan tests => 23;
-
-# 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 => [
-                        { 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, 3, 'Paul had two co-producers');
-  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,
-    3,
-    'Lars produced 3 CDs with bob',
-  );
-
-  my $bob_prod = $cd_rs->search (
-    { 'producer.name' => 'bob'},
-    { join => { cd_to_producer => 'producer' } }
-  );
-  is ($bob_prod->count, 4, 'Bob produced a total of 4 CDs');
-  ok ($bob_prod->find ({ title => 'Greatest hits 1'}), '1st Bob production name correct');
-  ok ($bob_prod->find ({ title => 'Greatest hits 6'}), '2nd Bob production name correct');
-  ok ($bob_prod->find ({ title => 'Greatest hits 2'}), '3rd Bob production name correct');
-  ok ($bob_prod->find ({ title => 'Greatest hits 7'}), '4th Bob production name correct');
-
-  is (
-    $bob_prod->search ({ 'artist.name' => 'james' }, { join => 'artist' })->count,
-    1,
-    "Bob produced james' only CD",
-  );
-};
-diag $@ if $@;
-
-1;

Added: DBIx-Class/0.08/branches/sybase/t/count/count_rs.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/count/count_rs.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/sybase/t/count/count_rs.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -0,0 +1,119 @@
+use strict;
+use warnings;
+
+use lib qw(t/lib);
+
+use Test::More;
+use DBICTest;
+use DBIC::SqlMakerTest;
+use DBIC::DebugObj;
+
+plan tests => 10;
+
+my $schema = DBICTest->init_schema();
+
+# non-collapsing prefetch (no multi prefetches)
+{
+  my $rs = $schema->resultset("CD")
+            ->search_related('tracks',
+                { position => [1,2] },
+                { prefetch => [qw/disc lyrics/], rows => 3, offset => 8 },
+            );
+  is ($rs->all, 2, 'Correct number of objects');
+
+
+  my ($sql, @bind);
+  $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
+  $schema->storage->debug(1);
+
+  is ($rs->count, 2, 'Correct count via count()');
+
+  is_same_sql_bind (
+    $sql,
+    \@bind,
+    'SELECT COUNT( * )
+      FROM cd me
+      LEFT JOIN track tracks ON tracks.cd = me.cdid
+      JOIN cd disc ON disc.cdid = tracks.cd
+      LEFT JOIN lyrics lyrics ON lyrics.track_id = tracks.trackid 
+     WHERE ( ( position = ? OR position = ? ) )
+    ',
+    [ qw/'1' '2'/ ],
+    'count softlimit applied',
+  );
+
+  my $crs = $rs->count_rs;
+  is ($crs->next, 2, 'Correct count via count_rs()');
+
+  is_same_sql_bind (
+    $crs->as_query,
+    '(SELECT COUNT( * )
+       FROM (
+        SELECT tracks.trackid
+          FROM cd me
+          LEFT JOIN track tracks ON tracks.cd = me.cdid
+          JOIN cd disc ON disc.cdid = tracks.cd
+          LEFT JOIN lyrics lyrics ON lyrics.track_id = tracks.trackid 
+        WHERE ( ( position = ? OR position = ? ) )
+        LIMIT 3 OFFSET 8
+       ) count_subq
+    )',
+    [ [ position => 1 ], [ position => 2 ] ],
+    'count_rs db-side limit applied',
+  );
+}
+
+# has_many prefetch with limit
+{
+  my $rs = $schema->resultset("Artist")
+            ->search_related('cds',
+                { 'tracks.position' => [1,2] },
+                { prefetch => [qw/tracks artist/], rows => 3, offset => 4 },
+            );
+  is ($rs->all, 1, 'Correct number of objects');
+
+  my ($sql, @bind);
+  $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
+  $schema->storage->debug(1);
+
+  is ($rs->count, 1, 'Correct count via count()');
+
+  is_same_sql_bind (
+    $sql,
+    \@bind,
+    'SELECT COUNT( * )
+      FROM (
+        SELECT cds.cdid
+          FROM artist me
+          LEFT JOIN cd cds ON cds.artist = me.artistid
+          LEFT JOIN track tracks ON tracks.cd = cds.cdid
+          JOIN artist artist ON artist.artistid = cds.artist
+        WHERE tracks.position = ? OR tracks.position = ?
+        GROUP BY cds.cdid
+      ) count_subq
+    ',
+    [ qw/'1' '2'/ ],
+    'count softlimit applied',
+  );
+
+  my $crs = $rs->count_rs;
+  is ($crs->next, 1, 'Correct count via count_rs()');
+
+  is_same_sql_bind (
+    $crs->as_query,
+    '(SELECT COUNT( * )
+      FROM (
+        SELECT cds.cdid
+          FROM artist me
+          LEFT JOIN cd cds ON cds.artist = me.artistid
+          LEFT JOIN track tracks ON tracks.cd = cds.cdid
+          JOIN artist artist ON artist.artistid = cds.artist
+        WHERE tracks.position = ? OR tracks.position = ?
+        GROUP BY cds.cdid
+        LIMIT 3 OFFSET 4
+      ) count_subq
+    )',
+    [ [ 'tracks.position' => 1 ], [ 'tracks.position' => 2 ] ],
+    'count_rs db-side limit applied',
+  );
+}

Modified: DBIx-Class/0.08/branches/sybase/t/count/distinct.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/count/distinct.t	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/t/count/distinct.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -11,9 +11,7 @@
 
 my $schema = DBICTest->init_schema();
 
-eval "use DBD::SQLite";
-plan skip_all => 'needs DBD::SQLite for testing' if $@;
-plan tests => 22;
+plan tests => 58;
 
 # The tag Blue is assigned to cds 1 2 3 and 5
 # The tag Cheesy is assigned to cds 2 4 and 5
@@ -23,59 +21,64 @@
 my $rs;
 my $in_rs = $schema->resultset('Tag')->search({ tag => [ 'Blue', 'Cheesy' ] });
 
-$rs = $schema->resultset('Tag')->search({ tag => 'Blue' });
-is($rs->count, 4, 'Count without DISTINCT');
+for my $get_count (
+  sub { shift->count },
+  sub { my $crs = shift->count_rs; isa_ok ($crs, 'DBIx::Class::ResultSetColumn'); $crs->next }
+) {
+  $rs = $schema->resultset('Tag')->search({ tag => 'Blue' });
+  is($get_count->($rs), 4, 'Count without DISTINCT');
 
-$rs = $schema->resultset('Tag')->search({ tag => [ 'Blue', 'Cheesy' ] }, { group_by => 'tag' });
-is($rs->count, 2, 'Count with single column group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => [ 'Blue', 'Cheesy' ] }, { group_by => 'tag' });
+  is($get_count->($rs), 2, 'Count with single column group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => [ 'Blue', 'Cheesy' ] }, { group_by => 'cd' });
-is($rs->count, 5, 'Count with another single column group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => [ 'Blue', 'Cheesy' ] }, { group_by => 'cd' });
+  is($get_count->($rs), 5, 'Count with another single column group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { group_by => [ qw/tag cd/ ]});
-is($rs->count, 4, 'Count with multiple column group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { group_by => [ qw/tag cd/ ]});
+  is($get_count->($rs), 4, 'Count with multiple column group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { distinct => 1 });
-is($rs->count, 4, 'Count with single column distinct');
+  $rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { distinct => 1 });
+  is($get_count->($rs), 4, 'Count with single column distinct');
 
-$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } });
-is($rs->count, 7, 'Count with IN subquery');
+  $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } });
+  is($get_count->($rs), 7, 'Count with IN subquery');
 
-$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { group_by => 'tag' });
-is($rs->count, 2, 'Count with IN subquery with outside group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { group_by => 'tag' });
+  is($get_count->($rs), 2, 'Count with IN subquery with outside group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1 });
-is($rs->count, 7, 'Count with IN subquery with outside distinct');
+  $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1 });
+  is($get_count->($rs), 7, 'Count with IN subquery with outside distinct');
 
-$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1, select => 'tag' }), 
-is($rs->count, 2, 'Count with IN subquery with outside distinct on a single column');
+  $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1, select => 'tag' }), 
+  is($get_count->($rs), 2, 'Count with IN subquery with outside distinct on a single column');
 
-$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => 'tag' })->get_column('tag')->as_query } });
-is($rs->count, 7, 'Count with IN subquery with single group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => 'tag' })->get_column('tag')->as_query } });
+  is($get_count->($rs), 7, 'Count with IN subquery with single group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => 'cd' })->get_column('tag')->as_query } });
-is($rs->count, 7, 'Count with IN subquery with another single group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => 'cd' })->get_column('tag')->as_query } });
+  is($get_count->($rs), 7, 'Count with IN subquery with another single group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => [ qw/tag cd/ ] })->get_column('tag')->as_query } });
-is($rs->count, 7, 'Count with IN subquery with multiple group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => [ qw/tag cd/ ] })->get_column('tag')->as_query } });
+  is($get_count->($rs), 7, 'Count with IN subquery with multiple group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => \"= 'Blue'" });
-is($rs->count, 4, 'Count without DISTINCT, using literal SQL');
+  $rs = $schema->resultset('Tag')->search({ tag => \"= 'Blue'" });
+  is($get_count->($rs), 4, 'Count without DISTINCT, using literal SQL');
 
-$rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Cheesy')" }, { group_by => 'tag' });
-is($rs->count, 2, 'Count with literal SQL and single group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Cheesy')" }, { group_by => 'tag' });
+  is($get_count->($rs), 2, 'Count with literal SQL and single group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Cheesy')" }, { group_by => 'cd' });
-is($rs->count, 5, 'Count with literal SQL and another single group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Cheesy')" }, { group_by => 'cd' });
+  is($get_count->($rs), 5, 'Count with literal SQL and another single group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Cheesy')" }, { group_by => [ qw/tag cd/ ] });
-is($rs->count, 7, 'Count with literal SQL and multiple group_by');
+  $rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Cheesy')" }, { group_by => [ qw/tag cd/ ] });
+  is($get_count->($rs), 7, 'Count with literal SQL and multiple group_by');
 
-$rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { '+select' => { max => 'tagid' }, distinct => 1 });
-is($rs->count, 4, 'Count with +select aggreggate');
+  $rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { '+select' => { max => 'tagid' }, distinct => 1 });
+  is($get_count->($rs), 4, 'Count with +select aggreggate');
 
-$rs = $schema->resultset('Tag')->search({}, { select => 'length(me.tag)', distinct => 1 });
-is($rs->count, 3, 'Count by distinct function result as select literal');
+  $rs = $schema->resultset('Tag')->search({}, { select => 'length(me.tag)', distinct => 1 });
+  is($get_count->($rs), 3, 'Count by distinct function result as select literal');
+}
 
 eval {
   my @warnings;
@@ -90,7 +93,7 @@
 
 throws_ok(
   sub { my $row = $schema->resultset('Tag')->search({}, { select => { distinct => [qw/tag cd/] } })->first },
-  qr/select => { distinct => ... } syntax is not supported for multiple columns/,
+  qr/select => { distinct => \.\.\. } syntax is not supported for multiple columns/,
   'throw on unsupported syntax'
 );
 

Modified: DBIx-Class/0.08/branches/sybase/t/inflate/serialize.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/inflate/serialize.t	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/t/inflate/serialize.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -32,7 +32,7 @@
 
 plan (skip_all => "No suitable serializer found") unless $selected;
 
-plan (tests => 8);
+plan (tests => 11);
 DBICTest::Schema::Serialized->inflate_column( 'serialized',
     { inflate => $selected->{inflater},
       deflate => $selected->{deflater},
@@ -84,3 +84,17 @@
 ok($object->update( { serialized => $struct_array } ), 'arrayref deflation');
 ok($inflated = $object->serialized, 'arrayref inflation');
 is_deeply($inflated, $struct_array, 'inflated array matches original');
+
+
+#===== make sure make_column_dirty ineracts reasonably with inflation
+$object = $rs->first;
+$object->update ({serialized => { x => 'y'}});
+
+$object->serialized->{x} = 'z'; # change state without notifying $object
+ok (!$object->get_dirty_columns, 'no dirty columns yet');
+is_deeply ($object->serialized, { x => 'z' }, 'object data correct');
+
+$object->make_column_dirty('serialized');
+$object->update;
+
+is_deeply ($rs->first->serialized, { x => 'z' }, 'changes made it to the db' );

Modified: DBIx-Class/0.08/branches/sybase/t/lib/DBICTest/Schema/Track.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/lib/DBICTest/Schema/Track.pm	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/t/lib/DBICTest/Schema/Track.pm	2009-06-24 05:43:53 UTC (rev 6779)
@@ -46,4 +46,6 @@
 __PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' );
 __PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' );
 
+__PACKAGE__->has_one( undying_lyric => 'DBICTest::Schema::Lyrics', 'track_id' );
+
 1;

Copied: DBIx-Class/0.08/branches/sybase/t/multi_create/in_memory.t (from rev 6490, DBIx-Class/0.08/branches/sybase/t/96multi_create_new.t)
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/multi_create/in_memory.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/sybase/t/multi_create/in_memory.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -0,0 +1,74 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan tests => 12;
+
+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_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode' });
+    my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave Slightly Noisily', 'year' => 1982});
+    eval {
+        $new_related_cd->insert;
+    };
+    is ($@, '', 'CD insertion survives by finding artist');
+    ok($new_artist->in_storage, 'artist inserted');
+    ok($new_related_cd->in_storage, 'new_related_cd inserted');
+}
+
+{
+    my $new_artist = $schema->resultset("Artist")->new_result({ 'name' => 'Depeche Mode 2: Insertion Boogaloo' });
+    my $new_related_cd = $new_artist->new_related('cds', { 'title' => 'Leave Loudly While Singing Off Key', 'year' => 1982});
+    eval {
+        $new_related_cd->insert;
+    };
+    is ($@, '', 'CD insertion survives by inserting artist');
+    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');
+}

Copied: DBIx-Class/0.08/branches/sybase/t/multi_create/standard.t (from rev 6490, DBIx-Class/0.08/branches/sybase/t/96multi_create.t)
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/multi_create/standard.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/sybase/t/multi_create/standard.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -0,0 +1,487 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan tests => 93;
+
+my $schema = DBICTest->init_schema();
+
+lives_ok ( sub {
+  my $cd = $schema->resultset('CD')->create({
+    artist => { 
+      name => 'Fred Bloggs' 
+    },
+    title => 'Some CD',
+    year => 1996
+  });
+
+  isa_ok($cd, 'DBICTest::CD', 'Created CD object');
+  isa_ok($cd->artist, 'DBICTest::Artist', 'Created related Artist');
+  is($cd->artist->name, 'Fred Bloggs', 'Artist created correctly');
+}, 'simple create + parent (the stuff $rs belongs_to) ok');
+
+lives_ok ( sub {
+  my $bm_rs = $schema->resultset('Bookmark');
+  my $bookmark = $bm_rs->create({
+    link => {
+      id => 66,
+    },
+  });
+
+  isa_ok($bookmark, 'DBICTest::Bookmark', 'Created Bookrmark object');
+  isa_ok($bookmark->link, 'DBICTest::Link', 'Created related Link');
+  is (
+    $bm_rs->search (
+      { 'link.title' => $bookmark->link->title },
+      { join => 'link' },
+    )->count,
+    1,
+    'Bookmark and link made it to the DB',
+  );
+}, 'simple create where the child and parent have no values, except for an explicit parent pk ok');
+
+lives_ok ( sub {
+  my $artist = $schema->resultset('Artist')->first;
+  my $cd = $artist->create_related (cds => {
+    title => 'Music to code by',
+    year => 2007,
+    tags => [
+      { 'tag' => 'rock' },
+    ],
+  });
+
+  isa_ok($cd, 'DBICTest::CD', 'Created CD');
+  is($cd->title, 'Music to code by', 'CD created correctly');
+  is($cd->tags->count, 1, 'One tag created for CD');
+  is($cd->tags->first->tag, 'rock', 'Tag created correctly');
+
+}, 'create over > 1 levels of has_many create (A => { has_many => { B => has_many => C } } )');
+
+throws_ok (
+  sub {
+    # Create via update - add a new CD <--- THIS SHOULD HAVE NEVER WORKED!
+    $schema->resultset('Artist')->first->update({
+      cds => [
+        { title => 'Yet another CD',
+          year => 2006,
+        },
+      ],
+    });
+  },
+  qr/Recursive update is not supported over relationships of type multi/,
+  'create via update of multi relationships throws an exception'
+);
+
+lives_ok ( sub {
+  my $artist = $schema->resultset('Artist')->first;
+  my $c2p = $schema->resultset('CD_to_Producer')->create ({
+    cd => {
+      artist => $artist,
+      title => 'Bad investment',
+      year => 2008,
+      tracks => [
+        { title => 'Just buy' },
+        { title => 'Why did we do it' },
+        { title => 'Burn baby burn' },
+      ],
+    },
+    producer => {
+      name => 'Lehman Bros.',
+    },
+  });
+
+  isa_ok ($c2p, 'DBICTest::CD_to_Producer', 'Linker object created');
+  my $prod = $schema->resultset ('Producer')->find ({ name => 'Lehman Bros.' });
+  isa_ok ($prod, 'DBICTest::Producer', 'Producer row found');
+  is ($prod->cds->count, 1, 'Producer has one production');
+  my $cd = $prod->cds->first;
+  is ($cd->title, 'Bad investment', 'CD created correctly');
+  is ($cd->tracks->count, 3, 'CD has 3 tracks');
+}, 'Create m2m while originating in the linker table');
+
+
+#CD -> has_many -> Tracks -> might have -> Single -> has_many -> Tracks
+#                                               \
+#                                                \-> has_many \
+#                                                              --> CD2Producer
+#                                                /-> has_many /
+#                                               /
+#                                          Producer
+lives_ok ( sub {
+  my $artist = $schema->resultset('Artist')->first;
+  my $cd = $schema->resultset('CD')->create ({
+    artist => $artist,
+    title => 'Music to code by at night',
+    year => 2008,
+    tracks => [
+      {
+        title => 'Off by one again',
+      },
+      {
+        title => 'The dereferencer',
+        cd_single => {
+          artist => $artist,
+          year => 2008,
+          title => 'Was that a null (Single)',
+          tracks => [
+            { title => 'The dereferencer' },
+            { title => 'The dereferencer II' },
+          ],
+          cd_to_producer => [
+            {
+              producer => {
+                name => 'K&R',
+              }
+            },
+            {
+              producer => {
+                name => 'Don Knuth',
+              }
+            },
+          ]
+        },
+      },
+    ],
+  });
+
+  isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
+  is ($cd->title, 'Music to code by at night', 'Correct CD title');
+  is ($cd->tracks->count, 2, 'Two tracks on main CD');
+
+  my ($t1, $t2) = $cd->tracks->all;
+  is ($t1->title, 'Off by one again', 'Correct 1st track name');
+  is ($t1->cd_single, undef, 'No single for 1st track');
+  is ($t2->title, 'The dereferencer', 'Correct 2nd track name');
+  isa_ok ($t2->cd_single, 'DBICTest::CD', 'Created a single for 2nd track');
+
+  my $single = $t2->cd_single;
+  is ($single->tracks->count, 2, 'Two tracks on single CD');
+  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, 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',
+  );
+}, 'Create over > 1 levels of might_have with multiple has_many and multiple m2m but starting at a has_many level');
+
+#Track -> might have -> Single -> has_many -> Tracks
+#                           \
+#                            \-> has_many \
+#                                          --> CD2Producer
+#                            /-> has_many /
+#                           /
+#                       Producer
+lives_ok ( sub {
+  my $cd = $schema->resultset('CD')->first;
+  my $track = $schema->resultset('Track')->create ({
+    cd => $cd,
+    title => 'Multicreate rocks',
+    cd_single => {
+      artist => $cd->artist,
+      year => 2008,
+      title => 'Disemboweling MultiCreate',
+      tracks => [
+        { title => 'Why does mst write this way' },
+        { title => 'Chainsaw celebration' },
+        { title => 'Purl cleans up' },
+      ],
+      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',
+  );
+}, 'Create over > 1 levels of might_have with multiple has_many and multiple m2m but starting at the might_have directly');
+
+lives_ok ( sub {
+  my $artist = $schema->resultset('Artist')->first;
+  my $cd = $schema->resultset('CD')->create ({
+    artist => $artist,
+    title => 'Music to code by at twilight',
+    year => 2008,
+    artwork => {
+      images => [
+        { name => 'recursive descent' },
+        { name => 'tail packing' },
+      ],
+    },
+  });
+
+  isa_ok ($cd, 'DBICTest::CD', 'Main CD object created');
+  is ($cd->title, 'Music to code by at twilight', 'Correct CD title');
+  isa_ok ($cd->artwork, 'DBICTest::Artwork', 'Artwork created');
+
+  # this test might look weird, but it failed at one point, keep it there
+  my $art_obj = $cd->artwork;
+  ok ($art_obj->has_column_loaded ('cd_id'), 'PK/FK present on artwork object');
+  is ($art_obj->images->count, 2, 'Correct artwork image count via the new object');
+  is_deeply (
+    [ sort $art_obj->images->get_column ('name')->all ],
+    [ 'recursive descent', 'tail packing' ],
+    'Images named correctly in objects',
+  );
+
+  my $artwork = $schema->resultset('Artwork')->search (
+    { 'cd.title' => 'Music to code by at twilight' },
+    { join => 'cd' },
+  )->single;
+
+  is ($artwork->images->count, 2, 'Correct artwork image count via a new search');
+
+  is_deeply (
+    [ sort $artwork->images->get_column ('name')->all ],
+    [ 'recursive descent', 'tail packing' ],
+    'Images named correctly after search',
+  );
+}, 'Test might_have again but with a PK == FK in the middle (obviously not specified)');
+
+lives_ok ( sub {
+  my $cd = $schema->resultset('CD')->first;
+  my $track = $schema->resultset ('Track')->create ({
+    cd => $cd,
+    title => 'Black',
+    lyrics => {
+      lyric_versions => [
+        { text => 'The color black' },
+        { text => 'The colour black' },
+      ],
+    },
+  });
+
+  isa_ok ($track, 'DBICTest::Track', 'Main track object created');
+  is ($track->title, 'Black', 'Correct track title');
+  isa_ok ($track->lyrics, 'DBICTest::Lyrics', 'Lyrics created');
+
+  # this test might look weird, but it was failing at one point, keep it there
+  my $lyric_obj = $track->lyrics;
+  ok ($lyric_obj->has_column_loaded ('lyric_id'), 'PK present on lyric object');
+  ok ($lyric_obj->has_column_loaded ('track_id'), 'FK present on lyric object');
+  is ($lyric_obj->lyric_versions->count, 2, 'Correct lyric versions count via the new object');
+  is_deeply (
+    [ sort $lyric_obj->lyric_versions->get_column ('text')->all ],
+    [ 'The color black', 'The colour black' ],
+    'Lyrics text in objects matches',
+  );
+
+
+  my $lyric = $schema->resultset('Lyrics')->search (
+    { 'track.title' => 'Black' },
+    { join => 'track' },
+  )->single;
+
+  is ($lyric->lyric_versions->count, 2, 'Correct lyric versions count via a new search');
+
+  is_deeply (
+    [ sort $lyric->lyric_versions->get_column ('text')->all ],
+    [ 'The color black', 'The colour black' ],
+    'Lyrics text via search matches',
+  );
+}, 'Test might_have again but with just a PK and FK (neither specified) in the mid-table');
+
+lives_ok ( sub {
+  my $newartist2 = $schema->resultset('Artist')->find_or_create({ 
+    name => 'Fred 3',
+    cds => [
+      { 
+        title => 'Noah Act',
+        year => 2007,
+      },
+    ],
+  });
+  is($newartist2->name, 'Fred 3', 'Created new artist with cds via find_or_create');
+}, 'Nested find_or_create');
+
+lives_ok ( sub {
+  my $artist2 = $schema->resultset('Artist')->create({
+    name => 'Fred 4',
+    cds => [
+      {
+        title => 'Music to code by',
+        year => 2007,
+      },
+    ],
+    cds_unordered => [
+      {
+        title => 'Music to code by',
+        year => 2007,
+      },
+    ]
+  });
+
+  is($artist2->in_storage, 1, 'artist with duplicate rels inserted okay');
+}, 'Multiple same level has_many create');
+
+lives_ok ( sub {
+	my $artist = $schema->resultset('Artist')->first;
+	
+	my $cd_result = $artist->create_related('cds', {
+	
+		title => 'TestOneCD1',
+		year => 2007,
+		tracks => [
+			{ title => 'TrackOne' },
+			{ title => 'TrackTwo' },
+		],
+
+	});
+	
+	isa_ok( $cd_result, 'DBICTest::CD', "Got Good CD Class");
+	ok( $cd_result->title eq "TestOneCD1", "Got Expected Title");
+	
+	my $tracks = $cd_result->tracks;
+	
+	isa_ok( $tracks, 'DBIx::Class::ResultSet', 'Got Expected Tracks ResultSet');
+	
+	foreach my $track ($tracks->all)
+	{
+		isa_ok( $track, 'DBICTest::Track', 'Got Expected Track Class');
+	}
+}, 'First create_related pass');
+
+lives_ok ( sub {
+	my $artist = $schema->resultset('Artist')->first;
+	
+	my $cd_result = $artist->create_related('cds', {
+	
+		title => 'TestOneCD2',
+		year => 2007,
+		tracks => [
+			{ title => 'TrackOne' },
+			{ title => 'TrackTwo' },
+		],
+
+    liner_notes => { notes => 'I can haz liner notes?' },
+
+	});
+	
+	isa_ok( $cd_result, 'DBICTest::CD', "Got Good CD Class");
+	ok( $cd_result->title eq "TestOneCD2", "Got Expected Title");
+  ok( $cd_result->notes eq 'I can haz liner notes?', 'Liner notes');
+	
+	my $tracks = $cd_result->tracks;
+	
+	isa_ok( $tracks, 'DBIx::Class::ResultSet', "Got Expected Tracks ResultSet");
+	
+	foreach my $track ($tracks->all)
+	{
+		isa_ok( $track, 'DBICTest::Track', 'Got Expected Track Class');
+	}
+}, 'second create_related with same arguments');
+
+lives_ok ( sub {
+  my $cdp = $schema->resultset('CD_to_Producer')->create({
+    cd => { artist => 1, title => 'foo', year => 2000 },
+    producer => { name => 'jorge' }
+  });
+  ok($cdp, 'join table record created ok');
+}, 'create of parents of a record linker table');
+
+lives_ok ( sub {
+  my $kurt_cobain = { name => 'Kurt Cobain' };
+
+  my $in_utero = $schema->resultset('CD')->new({
+      title => 'In Utero',
+      year  => 1993
+    });
+
+  $kurt_cobain->{cds} = [ $in_utero ];
+
+
+  $schema->resultset('Artist')->populate([ $kurt_cobain ]); # %)
+  $a = $schema->resultset('Artist')->find({name => 'Kurt Cobain'});
+
+  is($a->name, 'Kurt Cobain', 'Artist insertion ok');
+  is($a->cds && $a->cds->first && $a->cds->first->title, 
+		  'In Utero', 'CD insertion ok');
+}, 'populate');
+
+## Create foreign key col obj including PK
+## See test 20 in 66relationships.t
+lives_ok ( sub {
+  my $new_cd_hashref = { 
+    cdid => 27, 
+    title => 'Boogie Woogie', 
+    year => '2007', 
+    artist => { artistid => 17, name => 'king luke' }
+  };
+
+  my $cd = $schema->resultset("CD")->find(1);
+
+  is($cd->artist->id, 1, 'rel okay');
+
+  my $new_cd = $schema->resultset("CD")->create($new_cd_hashref);
+  is($new_cd->artist->id, 17, 'new id retained okay');
+}, 'Create foreign key col obj including PK');
+
+lives_ok ( sub {
+	$schema->resultset("CD")->create({ 
+              cdid => 28, 
+              title => 'Boogie Wiggle', 
+              year => '2007', 
+              artist => { artistid => 18, name => 'larry' }
+             });
+}, 'new cd created without clash on related artist');
+
+throws_ok ( sub {
+    my $t = $schema->resultset("Track")->new({ cd => { artist => undef } });
+    #$t->cd($t->new_related('cd', { artist => undef } ) );
+    #$t->{_rel_in_storage} = 0;
+    $t->insert;
+}, qr/cd.artist may not be NULL/, "Exception propogated properly");
+
+lives_ok ( sub {
+  $schema->resultset('CD')->create ({
+    artist => {
+      name => 'larry', # should already exist
+    },
+    title => 'Warble Marble',
+    year => '2009',
+    cd_to_producer => [
+      { producer => { name => 'Cowboy Neal' } },
+    ],
+  });
+
+  my $m2m_cd = $schema->resultset('CD')->search ({ title => 'Warble Marble'});
+  is ($m2m_cd->count, 1, 'One CD row created via M2M create');
+  is ($m2m_cd->first->producers->count, 1, 'CD row created with one producer');
+  is ($m2m_cd->first->producers->first->name, 'Cowboy Neal', 'Correct producer row created');
+}, 'Test multi create over many_to_many');
+
+1;

Copied: DBIx-Class/0.08/branches/sybase/t/multi_create/torture.t (from rev 6490, DBIx-Class/0.08/branches/sybase/t/96multi_create_torture.t)
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/multi_create/torture.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/sybase/t/multi_create/torture.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -0,0 +1,228 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan tests => 23;
+
+# 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 => [
+                        { 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',
+        having => 'count(me.cdid) = 2',
+      }
+    ),
+    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, 3, 'Paul had two co-producers');
+  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,
+    3,
+    'Lars produced 3 CDs with bob',
+  );
+
+  my $bob_prod = $cd_rs->search (
+    { 'producer.name' => 'bob'},
+    { join => { cd_to_producer => 'producer' } }
+  );
+  is ($bob_prod->count, 4, 'Bob produced a total of 4 CDs');
+  ok ($bob_prod->find ({ title => 'Greatest hits 1'}), '1st Bob production name correct');
+  ok ($bob_prod->find ({ title => 'Greatest hits 6'}), '2nd Bob production name correct');
+  ok ($bob_prod->find ({ title => 'Greatest hits 2'}), '3rd Bob production name correct');
+  ok ($bob_prod->find ({ title => 'Greatest hits 7'}), '4th Bob production name correct');
+
+  is (
+    $bob_prod->search ({ 'artist.name' => 'james' }, { join => 'artist' })->count,
+    1,
+    "Bob produced james' only CD",
+  );
+};
+diag $@ if $@;
+
+1;

Modified: DBIx-Class/0.08/branches/sybase/t/prefetch/with_limit.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/prefetch/with_limit.t	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/t/prefetch/with_limit.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -14,19 +14,18 @@
 
 
 my $no_prefetch = $schema->resultset('Artist')->search(
-  undef,
-  { rows => 3 }
-);
-
-my $use_prefetch = $schema->resultset('Artist')->search(
   [   # search deliberately contrived
     { 'artwork.cd_id' => undef },
     { 'tracks.title' => { '!=' => 'blah-blah-1234568' }}
   ],
+  { rows => 3, join => { cds => [qw/artwork tracks/] },
+ }
+);
+
+my $use_prefetch = $no_prefetch->search(
+  {},
   {
     prefetch => 'cds',
-    join => { cds => [qw/artwork tracks/] },
-    rows     => 3,
     order_by => { -desc => 'name' },
   }
 );

Modified: DBIx-Class/0.08/branches/sybase/t/relationship/core.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/relationship/core.t	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/t/relationship/core.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -40,8 +40,8 @@
       year => 2005,
   } );
 
- SKIP:{
-    skip "Can't fix right now", 1 if $DBIx::Class::VERSION < 0.09;
+ TODO: {
+    local $TODO = "Can't fix right now" if $DBIx::Class::VERSION < 0.09;
     lives_ok { $big_flop->genre} "Don't throw exception when col is not loaded after insert";
   };
 }

Modified: DBIx-Class/0.08/branches/sybase/t/zzzzzzz_perl_perf_bug.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/zzzzzzz_perl_perf_bug.t	2009-06-24 05:33:16 UTC (rev 6778)
+++ DBIx-Class/0.08/branches/sybase/t/zzzzzzz_perl_perf_bug.t	2009-06-24 05:43:53 UTC (rev 6779)
@@ -68,7 +68,7 @@
     "in the Troubleshooting POD documentation entitled\n",
     "'Perl Performance Issues on Red Hat Systems'\n",
     "As this is an extremely serious condition, the only way to skip\n",
-    "over this test is to --force the installation, or to edit the test\n",
+    "over this test is to --force the installation, or to look in the test\n",
     "file " . __FILE__ . "\n",
   );
 
@@ -115,7 +115,7 @@
         "Please read the section in the Troubleshooting POD documentation\n",
         "entitled 'Perl Performance Issues on Red Hat Systems'\n",
         "As this is an extremely serious condition, the only way to skip\n",
-        "over this test is to --force the installation, or to edit the test\n",
+        "over this test is to --force the installation, or to look in the test\n",
         "file " . __FILE__ . "\n",
       );
 }




More information about the Bast-commits mailing list