[Bast-commits] r6499 - in DBIx-Class/0.08/branches/sybase: .
lib/DBIx/Class lib/DBIx/Class/Storage t t/relationship
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Thu Jun 4 09:55:52 GMT 2009
Author: caelum
Date: 2009-06-04 09:55:52 +0000 (Thu, 04 Jun 2009)
New Revision: 6499
Added:
DBIx-Class/0.08/branches/sybase/t/relationship/
DBIx-Class/0.08/branches/sybase/t/relationship/after_update.t
DBIx-Class/0.08/branches/sybase/t/relationship/core.t
DBIx-Class/0.08/branches/sybase/t/relationship/doesnt_exist.t
Removed:
DBIx-Class/0.08/branches/sybase/t/66relationship.t
DBIx-Class/0.08/branches/sybase/t/relationship_after_update.t
DBIx-Class/0.08/branches/sybase/t/relationship_doesnt_exist.t
Modified:
DBIx-Class/0.08/branches/sybase/
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm
Log:
r5325 at hlagh (orig r6495): ribasushi | 2009-06-04 00:35:25 -0700
Move relationship tests around
r5328 at hlagh (orig r6498): ribasushi | 2009-06-04 02:52:18 -0700
Delegate actual counting to the storage class
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/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/replication_dedux:4600
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/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:6486
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/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/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/replication_dedux:4600
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/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:6498
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/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/ResultSet.pm 2009-06-04 09:52:18 UTC (rev 6498)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/ResultSet.pm 2009-06-04 09:55:52 UTC (rev 6499)
@@ -1176,6 +1176,7 @@
my ($self, $add_group_by) = @_;
my $attrs = $self->_resolved_attrs_copy;
+ my $rsrc = $self->result_source;
# copy for the subquery, we need to do some adjustments to it too
my $sub_attrs = { %$attrs };
@@ -1193,27 +1194,29 @@
delete $sub_attrs->{group_by};
}
- $sub_attrs->{columns} = $sub_attrs->{group_by} ||= [ map { "$attrs->{alias}.$_" } ($self->result_source->primary_columns) ];
+ $sub_attrs->{columns} = $sub_attrs->{group_by} ||= [ map { "$attrs->{alias}.$_" } ($rsrc->primary_columns) ];
}
$attrs->{from} = [{
- count_subq => (ref $self)->new ($self->result_source, $sub_attrs )->as_query
+ count_subq => (ref $self)->new ($rsrc, $sub_attrs )->as_query
}];
# the subquery replaces this
delete $attrs->{$_} for qw/where bind prefetch collapse distinct group_by having having_bind/;
- return $self->__count ($attrs);
+ return $rsrc->storage->count ($rsrc, $attrs);
}
sub _count_simple {
my $self = shift;
- my $count = $self->__count;
+ my $rsrc = $self->result_source;
+
+ # the attrs supplied here are getting modified, do not reuse below
+ my $count = $rsrc->storage->count ($rsrc, $self->_resolved_attrs_copy);
return 0 unless $count;
# need to take offset from resolved attrs
-
my $attrs = $self->_resolved_attrs;
$count -= $attrs->{offset} if $attrs->{offset};
@@ -1222,23 +1225,6 @@
return $count;
}
-sub __count {
- my ($self, $attrs) = @_;
-
- $attrs ||= $self->_resolved_attrs_copy;
-
- # take off any column specs, any pagers, record_filter is cdbi, and no point of ordering a count
- delete $attrs->{$_} for (qw/columns +columns select +select as +as rows offset page pager order_by record_filter/);
-
- $attrs->{select} = { count => '*' };
- $attrs->{as} = [qw/count/];
-
- my $tmp_rs = (ref $self)->new($self->result_source, $attrs);
- my ($count) = $tmp_rs->cursor->next;
-
- return $count;
-}
-
sub _bool {
return 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-04 09:52:18 UTC (rev 6498)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI.pm 2009-06-04 09:55:52 UTC (rev 6499)
@@ -1229,6 +1229,21 @@
return @args;
}
+sub count {
+ my ($self, $source, $attrs) = @_;
+
+ # take off any column specs, any pagers, record_filter is cdbi, and no point of ordering a count
+ delete $attrs->{$_} for (qw/columns +columns select +select as +as rows offset page pager order_by record_filter/);
+
+ $attrs->{select} = { count => '*' };
+ $attrs->{as} = [qw/count/];
+
+ my $tmp_rs = $source->resultset_class->new($source, $attrs);
+ my ($count) = $tmp_rs->cursor->next;
+
+ return $count;
+}
+
sub source_bind_attributes {
my ($self, $source) = @_;
Deleted: DBIx-Class/0.08/branches/sybase/t/66relationship.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/66relationship.t 2009-06-04 09:52:18 UTC (rev 6498)
+++ DBIx-Class/0.08/branches/sybase/t/66relationship.t 2009-06-04 09:55:52 UTC (rev 6499)
@@ -1,311 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use Test::Exception;
-use lib qw(t/lib);
-use DBICTest;
-
-my $schema = DBICTest->init_schema();
-
-plan tests => 78;
-
-# has_a test
-my $cd = $schema->resultset("CD")->find(4);
-my ($artist) = ($INC{'DBICTest/HelperRels'}
- ? $cd->artist
- : $cd->search_related('artist'));
-is($artist->name, 'Random Boy Band', 'has_a search_related ok');
-
-# has_many test with an order_by clause defined
-$artist = $schema->resultset("Artist")->find(1);
-my @cds = ($INC{'DBICTest/HelperRels'}
- ? $artist->cds
- : $artist->search_related('cds'));
-is( $cds[1]->title, 'Spoonful of bees', 'has_many search_related with order_by ok' );
-
-# search_related with additional abstract query
- at cds = ($INC{'DBICTest/HelperRels'}
- ? $artist->cds({ title => { like => '%of%' } })
- : $artist->search_related('cds', { title => { like => '%of%' } } )
- );
-is( $cds[1]->title, 'Forkful of bees', 'search_related with abstract query ok' );
-
-# creating a related object
-if ($INC{'DBICTest/HelperRels.pm'}) {
- $artist->add_to_cds({ title => 'Big Flop', year => 2005 });
-} else {
- my $big_flop = $artist->create_related( 'cds', {
- title => 'Big Flop',
- year => 2005,
- } );
-
- SKIP:{
- skip "Can't fix right now", 1 if $DBIx::Class::VERSION < 0.09;
- lives_ok { $big_flop->genre} "Don't throw exception when col is not loaded after insert";
- };
-}
-
-my $big_flop_cd = ($artist->search_related('cds'))[3];
-is( $big_flop_cd->title, 'Big Flop', 'create_related ok' );
-
-{ # make sure we are not making pointless select queries when a FK IS NULL
- my $queries = 0;
- $schema->storage->debugcb(sub { $queries++; });
- $schema->storage->debug(1);
- $big_flop_cd->genre; #should not trigger a select query
- is($queries, 0, 'No SELECT made for belongs_to if key IS NULL');
- $big_flop_cd->genre_inefficient; #should trigger a select query
- is($queries, 1, 'SELECT made for belongs_to if key IS NULL when undef_on_null_fk disabled');
- $schema->storage->debug(0);
- $schema->storage->debugcb(undef);
-}
-
-my( $rs_from_list ) = $artist->search_related_rs('cds');
-isa_ok( $rs_from_list, 'DBIx::Class::ResultSet', 'search_related_rs in list context returns rs' );
-
-( $rs_from_list ) = $artist->cds_rs();
-isa_ok( $rs_from_list, 'DBIx::Class::ResultSet', 'relation_rs in list context returns rs' );
-
-# count_related
-is( $artist->count_related('cds'), 4, 'count_related ok' );
-
-# set_from_related
-my $track = $schema->resultset("Track")->create( {
- trackid => 1,
- cd => 3,
- position => 98,
- title => 'Hidden Track'
-} );
-$track->set_from_related( cd => $cd );
-
-is($track->disc->cdid, 4, 'set_from_related ok, including alternative accessor' );
-
-$track->set_from_related( cd => undef );
-
-ok( !defined($track->cd), 'set_from_related with undef ok');
-
-TODO: {
- local $TODO = 'accessing $object->rel and set_from_related';
- my $track = $schema->resultset("Track")->new( {} );
- $track->cd;
- $track->set_from_related( cd => $cd );
- ok ($track->cd, 'set_from_related ok after using the accessor' );
-};
-
-# update_from_related, the same as set_from_related, but it calls update afterwards
-$track = $schema->resultset("Track")->create( {
- trackid => 2,
- cd => 3,
- title => 'Hidden Track 2'
-} );
-$track->update_from_related( cd => $cd );
-
-my $t_cd = ($schema->resultset("Track")->search( cd => 4, title => 'Hidden Track 2' ))[0]->cd;
-
-is( $t_cd->cdid, 4, 'update_from_related ok' );
-
-# find_or_create_related with an existing record
-$cd = $artist->find_or_create_related( 'cds', { title => 'Big Flop' } );
-is( $cd->year, 2005, 'find_or_create_related on existing record ok' );
-
-# find_or_create_related creating a new record
-$cd = $artist->find_or_create_related( 'cds', {
- title => 'Greatest Hits',
- year => 2006,
-} );
-is( $cd->title, 'Greatest Hits', 'find_or_create_related new record ok' );
-
- at cds = $artist->search_related('cds');
-is( ($artist->search_related('cds'))[4]->title, 'Greatest Hits', 'find_or_create_related new record search ok' );
-
-$artist->delete_related( cds => { title => 'Greatest Hits' });
-cmp_ok( $schema->resultset("CD")->search( title => 'Greatest Hits' ), '==', 0, 'delete_related ok' );
-
-# find_or_new_related with an existing record
-$cd = $artist->find_or_new_related( 'cds', { title => 'Big Flop' } );
-is( $cd->year, 2005, 'find_or_new_related on existing record ok' );
-ok( $cd->in_storage, 'find_or_new_related on existing record: is in_storage' );
-
-# find_or_new_related instantiating a new record
-$cd = $artist->find_or_new_related( 'cds', {
- title => 'Greatest Hits 2: Louder Than Ever',
- year => 2007,
-} );
-is( $cd->title, 'Greatest Hits 2: Louder Than Ever', 'find_or_new_related new record ok' );
-ok( ! $cd->in_storage, 'find_or_new_related on a new record: not in_storage' );
-
-$cd->artist(undef);
-my $newartist = $cd->find_or_new_related( 'artist', {
- name => 'Random Boy Band Two',
- artistid => 200,
-} );
-is($newartist->name, 'Random Boy Band Two', 'find_or_new_related new artist record with id');
-is($newartist->id, 200, 'find_or_new_related new artist id set');
-
-lives_ok(
- sub {
- my $new_bookmark = $schema->resultset("Bookmark")->new_result( {} );
- my $new_related_link = $new_bookmark->new_related( 'link', {} );
- },
- 'No back rel'
-);
-
-
-TODO: {
- local $TODO = "relationship checking needs fixing";
- # try to add a bogus relationship using the wrong cols
- eval {
- DBICTest::Schema::Artist->add_relationship(
- tracks => 'DBICTest::Schema::Track',
- { 'foreign.cd' => 'self.cdid' }
- );
- };
- like($@, qr/Unknown column/, 'failed when creating a rel with invalid key, ok');
-}
-
-# another bogus relationship using no join condition
-eval {
- DBICTest::Schema::Artist->add_relationship( tracks => 'DBICTest::Track' );
-};
-like($@, qr/join condition/, 'failed when creating a rel without join condition, ok');
-
-# many_to_many helper tests
-$cd = $schema->resultset("CD")->find(1);
-my @producers = $cd->producers();
-is( $producers[0]->name, 'Matt S Trout', 'many_to_many ok' );
-is( $cd->producers_sorted->next->name, 'Bob The Builder',
- 'sorted many_to_many ok' );
-is( $cd->producers_sorted(producerid => 3)->next->name, 'Fred The Phenotype',
- 'sorted many_to_many with search condition ok' );
-
-$cd = $schema->resultset('CD')->find(2);
-my $prod_rs = $cd->producers();
-my $prod_before_count = $schema->resultset('Producer')->count;
-is( $prod_rs->count, 0, "CD doesn't yet have any producers" );
-my $prod = $schema->resultset('Producer')->find(1);
-$cd->add_to_producers($prod);
-is( $prod_rs->count(), 1, 'many_to_many add_to_$rel($obj) count ok' );
-is( $prod_rs->first->name, 'Matt S Trout',
- 'many_to_many add_to_$rel($obj) ok' );
-$cd->remove_from_producers($prod);
-$cd->add_to_producers($prod, {attribute => 1});
-is( $prod_rs->count(), 1, 'many_to_many add_to_$rel($obj, $link_vals) count ok' );
-is( $cd->cd_to_producer->first->attribute, 1, 'many_to_many $link_vals ok');
-$cd->remove_from_producers($prod);
-$cd->set_producers([$prod], {attribute => 2});
-is( $prod_rs->count(), 1, 'many_to_many set_$rel($obj, $link_vals) count ok' );
-is( $cd->cd_to_producer->first->attribute, 2, 'many_to_many $link_vals ok');
-$cd->remove_from_producers($prod);
-is( $schema->resultset('Producer')->find(1)->name, 'Matt S Trout',
- "producer object exists after remove of link" );
-is( $prod_rs->count, 0, 'many_to_many remove_from_$rel($obj) ok' );
-$cd->add_to_producers({ name => 'Testy McProducer' });
-is( $schema->resultset('Producer')->count, $prod_before_count+1,
- 'add_to_$rel($hash) inserted a new producer' );
-is( $prod_rs->count(), 1, 'many_to_many add_to_$rel($hash) count ok' );
-is( $prod_rs->first->name, 'Testy McProducer',
- 'many_to_many add_to_$rel($hash) ok' );
-$cd->add_to_producers({ name => 'Jack Black' });
-is( $prod_rs->count(), 2, 'many_to_many add_to_$rel($hash) count ok' );
-$cd->set_producers($schema->resultset('Producer')->all);
-is( $cd->producers->count(), $prod_before_count+2,
- 'many_to_many set_$rel(@objs) count ok' );
-$cd->set_producers($schema->resultset('Producer')->find(1));
-is( $cd->producers->count(), 1, 'many_to_many set_$rel($obj) count ok' );
-$cd->set_producers([$schema->resultset('Producer')->all]);
-is( $cd->producers->count(), $prod_before_count+2,
- 'many_to_many set_$rel(\@objs) count ok' );
-$cd->set_producers([$schema->resultset('Producer')->find(1)]);
-is( $cd->producers->count(), 1, 'many_to_many set_$rel([$obj]) count ok' );
-
-eval { $cd->remove_from_producers({ fake => 'hash' }); };
-like( $@, qr/needs an object/, 'remove_from_$rel($hash) dies correctly' );
-
-eval { $cd->add_to_producers(); };
-like( $@, qr/needs an object or hashref/,
- 'add_to_$rel(undef) dies correctly' );
-
-# many_to_many stresstest
-my $twokey = $schema->resultset('TwoKeys')->find(1,1);
-my $fourkey = $schema->resultset('FourKeys')->find(1,2,3,4);
-
-is( $twokey->fourkeys->count, 0, 'twokey has no fourkeys' );
-$twokey->add_to_fourkeys($fourkey, { autopilot => 'engaged' });
-my $got_fourkey = $twokey->fourkeys({ sensors => 'online' })->first;
-is( $twokey->fourkeys->count, 1, 'twokey has one fourkey' );
-is( $got_fourkey->$_, $fourkey->$_,
- 'fourkeys row has the correct value for column '.$_ )
- for (qw(foo bar hello goodbye sensors));
-$twokey->remove_from_fourkeys($fourkey);
-is( $twokey->fourkeys->count, 0, 'twokey has no fourkeys' );
-is( $twokey->fourkeys_to_twokeys->count, 0,
- 'twokey has no links to fourkey' );
-
-
-my $undef_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007 });
-is($undef_artist_cd->has_column_loaded('artist'), '', 'FK not loaded');
-is($undef_artist_cd->search_related('artist')->count, 0, '0=1 search when FK does not exist and object not yet in db');
-eval{
- $undef_artist_cd->related_resultset('artist')->new({name => 'foo'});
-};
-is( $@, '', "Object created on a resultset related to not yet inserted object");
-lives_ok{
- $schema->resultset('Artwork')->new_result({})->cd;
-} 'undef_on_null_fk does not choke on empty conds';
-
-my $def_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007, artist => undef });
-is($def_artist_cd->has_column_loaded('artist'), 1, 'FK loaded');
-is($def_artist_cd->search_related('artist')->count, 0, 'closed search on null FK');
-
-# test undirected many-to-many relationship (e.g. "related artists")
-my $undir_maps = $schema->resultset("Artist")->find(1)->artist_undirected_maps;
-is($undir_maps->count, 1, 'found 1 undirected map for artist 1');
-
-$undir_maps = $schema->resultset("Artist")->find(2)->artist_undirected_maps;
-is($undir_maps->count, 1, 'found 1 undirected map for artist 2');
-
-my $mapped_rs = $undir_maps->search_related('mapped_artists');
-
-my @art = $mapped_rs->all;
-
-cmp_ok(@art, '==', 2, "Both artist returned from map");
-
-my $searched = $mapped_rs->search({'mapped_artists.artistid' => {'!=', undef}});
-
-cmp_ok($searched->count, '==', 2, "Both artist returned from map after adding another condition");
-
-# check join through cascaded has_many relationships
-$artist = $schema->resultset("Artist")->find(1);
-my $trackset = $artist->cds->search_related('tracks');
-# LEFT join means we also see the trackless additional album...
-cmp_ok($trackset->count, '==', 11, "Correct number of tracks for artist");
-
-# now see about updating eveything that belongs to artist 2 to artist 3
-$artist = $schema->resultset("Artist")->find(2);
-my $nartist = $schema->resultset("Artist")->find(3);
-cmp_ok($artist->cds->count, '==', 1, "Correct orig #cds for artist");
-cmp_ok($nartist->cds->count, '==', 1, "Correct orig #cds for artist");
-$artist->cds->update({artist => $nartist->id});
-cmp_ok($artist->cds->count, '==', 0, "Correct new #cds for artist");
-cmp_ok($nartist->cds->count, '==', 2, "Correct new #cds for artist");
-
-# check if is_foreign_key_constraint attr is set
-my $rs_normal = $schema->source('Track');
-my $relinfo = $rs_normal->relationship_info ('cd');
-cmp_ok($relinfo->{attrs}{is_foreign_key_constraint}, '==', 1, "is_foreign_key_constraint defined for belongs_to relationships.");
-
-my $rs_overridden = $schema->source('ForceForeign');
-my $relinfo_with_attr = $rs_overridden->relationship_info ('cd_3');
-cmp_ok($relinfo_with_attr->{attrs}{is_foreign_key_constraint}, '==', 0, "is_foreign_key_constraint defined for belongs_to relationships with attr.");
-
-# check that relationships below left join relationships are forced to left joins
-# when traversing multiple belongs_to
-my $cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => 'cd' } });
-is($cds->count, 1, "subjoins under left joins force_left (string)");
-
-$cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => ['cd'] } });
-is($cds->count, 1, "subjoins under left joins force_left (arrayref)");
-
-$cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => { cd => {} } } });
-is($cds->count, 1, "subjoins under left joins force_left (hashref)");
Copied: DBIx-Class/0.08/branches/sybase/t/relationship/after_update.t (from rev 6490, DBIx-Class/0.08/branches/sybase/t/relationship_after_update.t)
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/relationship/after_update.t (rev 0)
+++ DBIx-Class/0.08/branches/sybase/t/relationship/after_update.t 2009-06-04 09:55:52 UTC (rev 6499)
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 2;
+
+my $bookmark = $schema->resultset("Bookmark")->find(1);
+my $link = $bookmark->link;
+my $link_id = $link->id;
+
+my $new_link = $schema->resultset("Link")->new({
+ id => 42,
+ url => "http://monstersarereal.com",
+ title => "monstersarereal.com"
+});
+
+# Changing a relationship by id rather than by object would cause
+# old related_resultsets to be used.
+$bookmark->link($new_link->id);
+is $bookmark->link->id, $new_link->id;
+
+$bookmark->update;
+is $bookmark->link->id, $new_link->id;
Copied: DBIx-Class/0.08/branches/sybase/t/relationship/core.t (from rev 6490, DBIx-Class/0.08/branches/sybase/t/66relationship.t)
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/relationship/core.t (rev 0)
+++ DBIx-Class/0.08/branches/sybase/t/relationship/core.t 2009-06-04 09:55:52 UTC (rev 6499)
@@ -0,0 +1,311 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 78;
+
+# has_a test
+my $cd = $schema->resultset("CD")->find(4);
+my ($artist) = ($INC{'DBICTest/HelperRels'}
+ ? $cd->artist
+ : $cd->search_related('artist'));
+is($artist->name, 'Random Boy Band', 'has_a search_related ok');
+
+# has_many test with an order_by clause defined
+$artist = $schema->resultset("Artist")->find(1);
+my @cds = ($INC{'DBICTest/HelperRels'}
+ ? $artist->cds
+ : $artist->search_related('cds'));
+is( $cds[1]->title, 'Spoonful of bees', 'has_many search_related with order_by ok' );
+
+# search_related with additional abstract query
+ at cds = ($INC{'DBICTest/HelperRels'}
+ ? $artist->cds({ title => { like => '%of%' } })
+ : $artist->search_related('cds', { title => { like => '%of%' } } )
+ );
+is( $cds[1]->title, 'Forkful of bees', 'search_related with abstract query ok' );
+
+# creating a related object
+if ($INC{'DBICTest/HelperRels.pm'}) {
+ $artist->add_to_cds({ title => 'Big Flop', year => 2005 });
+} else {
+ my $big_flop = $artist->create_related( 'cds', {
+ title => 'Big Flop',
+ year => 2005,
+ } );
+
+ SKIP:{
+ skip "Can't fix right now", 1 if $DBIx::Class::VERSION < 0.09;
+ lives_ok { $big_flop->genre} "Don't throw exception when col is not loaded after insert";
+ };
+}
+
+my $big_flop_cd = ($artist->search_related('cds'))[3];
+is( $big_flop_cd->title, 'Big Flop', 'create_related ok' );
+
+{ # make sure we are not making pointless select queries when a FK IS NULL
+ my $queries = 0;
+ $schema->storage->debugcb(sub { $queries++; });
+ $schema->storage->debug(1);
+ $big_flop_cd->genre; #should not trigger a select query
+ is($queries, 0, 'No SELECT made for belongs_to if key IS NULL');
+ $big_flop_cd->genre_inefficient; #should trigger a select query
+ is($queries, 1, 'SELECT made for belongs_to if key IS NULL when undef_on_null_fk disabled');
+ $schema->storage->debug(0);
+ $schema->storage->debugcb(undef);
+}
+
+my( $rs_from_list ) = $artist->search_related_rs('cds');
+isa_ok( $rs_from_list, 'DBIx::Class::ResultSet', 'search_related_rs in list context returns rs' );
+
+( $rs_from_list ) = $artist->cds_rs();
+isa_ok( $rs_from_list, 'DBIx::Class::ResultSet', 'relation_rs in list context returns rs' );
+
+# count_related
+is( $artist->count_related('cds'), 4, 'count_related ok' );
+
+# set_from_related
+my $track = $schema->resultset("Track")->create( {
+ trackid => 1,
+ cd => 3,
+ position => 98,
+ title => 'Hidden Track'
+} );
+$track->set_from_related( cd => $cd );
+
+is($track->disc->cdid, 4, 'set_from_related ok, including alternative accessor' );
+
+$track->set_from_related( cd => undef );
+
+ok( !defined($track->cd), 'set_from_related with undef ok');
+
+TODO: {
+ local $TODO = 'accessing $object->rel and set_from_related';
+ my $track = $schema->resultset("Track")->new( {} );
+ $track->cd;
+ $track->set_from_related( cd => $cd );
+ ok ($track->cd, 'set_from_related ok after using the accessor' );
+};
+
+# update_from_related, the same as set_from_related, but it calls update afterwards
+$track = $schema->resultset("Track")->create( {
+ trackid => 2,
+ cd => 3,
+ title => 'Hidden Track 2'
+} );
+$track->update_from_related( cd => $cd );
+
+my $t_cd = ($schema->resultset("Track")->search( cd => 4, title => 'Hidden Track 2' ))[0]->cd;
+
+is( $t_cd->cdid, 4, 'update_from_related ok' );
+
+# find_or_create_related with an existing record
+$cd = $artist->find_or_create_related( 'cds', { title => 'Big Flop' } );
+is( $cd->year, 2005, 'find_or_create_related on existing record ok' );
+
+# find_or_create_related creating a new record
+$cd = $artist->find_or_create_related( 'cds', {
+ title => 'Greatest Hits',
+ year => 2006,
+} );
+is( $cd->title, 'Greatest Hits', 'find_or_create_related new record ok' );
+
+ at cds = $artist->search_related('cds');
+is( ($artist->search_related('cds'))[4]->title, 'Greatest Hits', 'find_or_create_related new record search ok' );
+
+$artist->delete_related( cds => { title => 'Greatest Hits' });
+cmp_ok( $schema->resultset("CD")->search( title => 'Greatest Hits' ), '==', 0, 'delete_related ok' );
+
+# find_or_new_related with an existing record
+$cd = $artist->find_or_new_related( 'cds', { title => 'Big Flop' } );
+is( $cd->year, 2005, 'find_or_new_related on existing record ok' );
+ok( $cd->in_storage, 'find_or_new_related on existing record: is in_storage' );
+
+# find_or_new_related instantiating a new record
+$cd = $artist->find_or_new_related( 'cds', {
+ title => 'Greatest Hits 2: Louder Than Ever',
+ year => 2007,
+} );
+is( $cd->title, 'Greatest Hits 2: Louder Than Ever', 'find_or_new_related new record ok' );
+ok( ! $cd->in_storage, 'find_or_new_related on a new record: not in_storage' );
+
+$cd->artist(undef);
+my $newartist = $cd->find_or_new_related( 'artist', {
+ name => 'Random Boy Band Two',
+ artistid => 200,
+} );
+is($newartist->name, 'Random Boy Band Two', 'find_or_new_related new artist record with id');
+is($newartist->id, 200, 'find_or_new_related new artist id set');
+
+lives_ok(
+ sub {
+ my $new_bookmark = $schema->resultset("Bookmark")->new_result( {} );
+ my $new_related_link = $new_bookmark->new_related( 'link', {} );
+ },
+ 'No back rel'
+);
+
+
+TODO: {
+ local $TODO = "relationship checking needs fixing";
+ # try to add a bogus relationship using the wrong cols
+ eval {
+ DBICTest::Schema::Artist->add_relationship(
+ tracks => 'DBICTest::Schema::Track',
+ { 'foreign.cd' => 'self.cdid' }
+ );
+ };
+ like($@, qr/Unknown column/, 'failed when creating a rel with invalid key, ok');
+}
+
+# another bogus relationship using no join condition
+eval {
+ DBICTest::Schema::Artist->add_relationship( tracks => 'DBICTest::Track' );
+};
+like($@, qr/join condition/, 'failed when creating a rel without join condition, ok');
+
+# many_to_many helper tests
+$cd = $schema->resultset("CD")->find(1);
+my @producers = $cd->producers();
+is( $producers[0]->name, 'Matt S Trout', 'many_to_many ok' );
+is( $cd->producers_sorted->next->name, 'Bob The Builder',
+ 'sorted many_to_many ok' );
+is( $cd->producers_sorted(producerid => 3)->next->name, 'Fred The Phenotype',
+ 'sorted many_to_many with search condition ok' );
+
+$cd = $schema->resultset('CD')->find(2);
+my $prod_rs = $cd->producers();
+my $prod_before_count = $schema->resultset('Producer')->count;
+is( $prod_rs->count, 0, "CD doesn't yet have any producers" );
+my $prod = $schema->resultset('Producer')->find(1);
+$cd->add_to_producers($prod);
+is( $prod_rs->count(), 1, 'many_to_many add_to_$rel($obj) count ok' );
+is( $prod_rs->first->name, 'Matt S Trout',
+ 'many_to_many add_to_$rel($obj) ok' );
+$cd->remove_from_producers($prod);
+$cd->add_to_producers($prod, {attribute => 1});
+is( $prod_rs->count(), 1, 'many_to_many add_to_$rel($obj, $link_vals) count ok' );
+is( $cd->cd_to_producer->first->attribute, 1, 'many_to_many $link_vals ok');
+$cd->remove_from_producers($prod);
+$cd->set_producers([$prod], {attribute => 2});
+is( $prod_rs->count(), 1, 'many_to_many set_$rel($obj, $link_vals) count ok' );
+is( $cd->cd_to_producer->first->attribute, 2, 'many_to_many $link_vals ok');
+$cd->remove_from_producers($prod);
+is( $schema->resultset('Producer')->find(1)->name, 'Matt S Trout',
+ "producer object exists after remove of link" );
+is( $prod_rs->count, 0, 'many_to_many remove_from_$rel($obj) ok' );
+$cd->add_to_producers({ name => 'Testy McProducer' });
+is( $schema->resultset('Producer')->count, $prod_before_count+1,
+ 'add_to_$rel($hash) inserted a new producer' );
+is( $prod_rs->count(), 1, 'many_to_many add_to_$rel($hash) count ok' );
+is( $prod_rs->first->name, 'Testy McProducer',
+ 'many_to_many add_to_$rel($hash) ok' );
+$cd->add_to_producers({ name => 'Jack Black' });
+is( $prod_rs->count(), 2, 'many_to_many add_to_$rel($hash) count ok' );
+$cd->set_producers($schema->resultset('Producer')->all);
+is( $cd->producers->count(), $prod_before_count+2,
+ 'many_to_many set_$rel(@objs) count ok' );
+$cd->set_producers($schema->resultset('Producer')->find(1));
+is( $cd->producers->count(), 1, 'many_to_many set_$rel($obj) count ok' );
+$cd->set_producers([$schema->resultset('Producer')->all]);
+is( $cd->producers->count(), $prod_before_count+2,
+ 'many_to_many set_$rel(\@objs) count ok' );
+$cd->set_producers([$schema->resultset('Producer')->find(1)]);
+is( $cd->producers->count(), 1, 'many_to_many set_$rel([$obj]) count ok' );
+
+eval { $cd->remove_from_producers({ fake => 'hash' }); };
+like( $@, qr/needs an object/, 'remove_from_$rel($hash) dies correctly' );
+
+eval { $cd->add_to_producers(); };
+like( $@, qr/needs an object or hashref/,
+ 'add_to_$rel(undef) dies correctly' );
+
+# many_to_many stresstest
+my $twokey = $schema->resultset('TwoKeys')->find(1,1);
+my $fourkey = $schema->resultset('FourKeys')->find(1,2,3,4);
+
+is( $twokey->fourkeys->count, 0, 'twokey has no fourkeys' );
+$twokey->add_to_fourkeys($fourkey, { autopilot => 'engaged' });
+my $got_fourkey = $twokey->fourkeys({ sensors => 'online' })->first;
+is( $twokey->fourkeys->count, 1, 'twokey has one fourkey' );
+is( $got_fourkey->$_, $fourkey->$_,
+ 'fourkeys row has the correct value for column '.$_ )
+ for (qw(foo bar hello goodbye sensors));
+$twokey->remove_from_fourkeys($fourkey);
+is( $twokey->fourkeys->count, 0, 'twokey has no fourkeys' );
+is( $twokey->fourkeys_to_twokeys->count, 0,
+ 'twokey has no links to fourkey' );
+
+
+my $undef_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007 });
+is($undef_artist_cd->has_column_loaded('artist'), '', 'FK not loaded');
+is($undef_artist_cd->search_related('artist')->count, 0, '0=1 search when FK does not exist and object not yet in db');
+eval{
+ $undef_artist_cd->related_resultset('artist')->new({name => 'foo'});
+};
+is( $@, '', "Object created on a resultset related to not yet inserted object");
+lives_ok{
+ $schema->resultset('Artwork')->new_result({})->cd;
+} 'undef_on_null_fk does not choke on empty conds';
+
+my $def_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007, artist => undef });
+is($def_artist_cd->has_column_loaded('artist'), 1, 'FK loaded');
+is($def_artist_cd->search_related('artist')->count, 0, 'closed search on null FK');
+
+# test undirected many-to-many relationship (e.g. "related artists")
+my $undir_maps = $schema->resultset("Artist")->find(1)->artist_undirected_maps;
+is($undir_maps->count, 1, 'found 1 undirected map for artist 1');
+
+$undir_maps = $schema->resultset("Artist")->find(2)->artist_undirected_maps;
+is($undir_maps->count, 1, 'found 1 undirected map for artist 2');
+
+my $mapped_rs = $undir_maps->search_related('mapped_artists');
+
+my @art = $mapped_rs->all;
+
+cmp_ok(@art, '==', 2, "Both artist returned from map");
+
+my $searched = $mapped_rs->search({'mapped_artists.artistid' => {'!=', undef}});
+
+cmp_ok($searched->count, '==', 2, "Both artist returned from map after adding another condition");
+
+# check join through cascaded has_many relationships
+$artist = $schema->resultset("Artist")->find(1);
+my $trackset = $artist->cds->search_related('tracks');
+# LEFT join means we also see the trackless additional album...
+cmp_ok($trackset->count, '==', 11, "Correct number of tracks for artist");
+
+# now see about updating eveything that belongs to artist 2 to artist 3
+$artist = $schema->resultset("Artist")->find(2);
+my $nartist = $schema->resultset("Artist")->find(3);
+cmp_ok($artist->cds->count, '==', 1, "Correct orig #cds for artist");
+cmp_ok($nartist->cds->count, '==', 1, "Correct orig #cds for artist");
+$artist->cds->update({artist => $nartist->id});
+cmp_ok($artist->cds->count, '==', 0, "Correct new #cds for artist");
+cmp_ok($nartist->cds->count, '==', 2, "Correct new #cds for artist");
+
+# check if is_foreign_key_constraint attr is set
+my $rs_normal = $schema->source('Track');
+my $relinfo = $rs_normal->relationship_info ('cd');
+cmp_ok($relinfo->{attrs}{is_foreign_key_constraint}, '==', 1, "is_foreign_key_constraint defined for belongs_to relationships.");
+
+my $rs_overridden = $schema->source('ForceForeign');
+my $relinfo_with_attr = $rs_overridden->relationship_info ('cd_3');
+cmp_ok($relinfo_with_attr->{attrs}{is_foreign_key_constraint}, '==', 0, "is_foreign_key_constraint defined for belongs_to relationships with attr.");
+
+# check that relationships below left join relationships are forced to left joins
+# when traversing multiple belongs_to
+my $cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => 'cd' } });
+is($cds->count, 1, "subjoins under left joins force_left (string)");
+
+$cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => ['cd'] } });
+is($cds->count, 1, "subjoins under left joins force_left (arrayref)");
+
+$cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => { cd => {} } } });
+is($cds->count, 1, "subjoins under left joins force_left (hashref)");
Copied: DBIx-Class/0.08/branches/sybase/t/relationship/doesnt_exist.t (from rev 6490, DBIx-Class/0.08/branches/sybase/t/relationship_doesnt_exist.t)
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/relationship/doesnt_exist.t (rev 0)
+++ DBIx-Class/0.08/branches/sybase/t/relationship/doesnt_exist.t 2009-06-04 09:55:52 UTC (rev 6499)
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 3;
+
+my $bookmark = $schema->resultset("Bookmark")->find(1);
+my $link = $bookmark->link;
+my $link_id = $link->id;
+ok $link->id;
+
+$link->delete;
+is $schema->resultset("Link")->search(id => $link_id)->count, 0,
+ "link $link_id was deleted";
+
+# Get a fresh object with nothing cached
+$bookmark = $schema->resultset("Bookmark")->find($bookmark->id);
+
+# This would create a new link row if none existed
+$bookmark->link;
+
+is $schema->resultset("Link")->search(id => $link_id)->count, 0,
+ 'accessor did not create a link object where there was none';
Deleted: DBIx-Class/0.08/branches/sybase/t/relationship_after_update.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/relationship_after_update.t 2009-06-04 09:52:18 UTC (rev 6498)
+++ DBIx-Class/0.08/branches/sybase/t/relationship_after_update.t 2009-06-04 09:55:52 UTC (rev 6499)
@@ -1,30 +0,0 @@
-#!/usr/bin/perl -w
-
-use strict;
-use warnings;
-
-use Test::More;
-use lib qw(t/lib);
-use DBICTest;
-
-my $schema = DBICTest->init_schema();
-
-plan tests => 2;
-
-my $bookmark = $schema->resultset("Bookmark")->find(1);
-my $link = $bookmark->link;
-my $link_id = $link->id;
-
-my $new_link = $schema->resultset("Link")->new({
- id => 42,
- url => "http://monstersarereal.com",
- title => "monstersarereal.com"
-});
-
-# Changing a relationship by id rather than by object would cause
-# old related_resultsets to be used.
-$bookmark->link($new_link->id);
-is $bookmark->link->id, $new_link->id;
-
-$bookmark->update;
-is $bookmark->link->id, $new_link->id;
Deleted: DBIx-Class/0.08/branches/sybase/t/relationship_doesnt_exist.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/relationship_doesnt_exist.t 2009-06-04 09:52:18 UTC (rev 6498)
+++ DBIx-Class/0.08/branches/sybase/t/relationship_doesnt_exist.t 2009-06-04 09:55:52 UTC (rev 6499)
@@ -1,30 +0,0 @@
-#!/usr/bin/perl -w
-
-use strict;
-use warnings;
-
-use Test::More;
-use lib qw(t/lib);
-use DBICTest;
-
-my $schema = DBICTest->init_schema();
-
-plan tests => 3;
-
-my $bookmark = $schema->resultset("Bookmark")->find(1);
-my $link = $bookmark->link;
-my $link_id = $link->id;
-ok $link->id;
-
-$link->delete;
-is $schema->resultset("Link")->search(id => $link_id)->count, 0,
- "link $link_id was deleted";
-
-# Get a fresh object with nothing cached
-$bookmark = $schema->resultset("Bookmark")->find($bookmark->id);
-
-# This would create a new link row if none existed
-$bookmark->link;
-
-is $schema->resultset("Link")->search(id => $link_id)->count, 0,
- 'accessor did not create a link object where there was none';
More information about the Bast-commits
mailing list