[Bast-commits] r6198 - in DBIx-Class/0.08/trunk: lib/DBIx/Class/Relationship t t/lib t/lib/DBICTest/Schema

mo at dev.catalyst.perl.org mo at dev.catalyst.perl.org
Sun May 10 15:37:16 GMT 2009


Author: mo
Date: 2009-05-10 15:37:16 +0000 (Sun, 10 May 2009)
New Revision: 6198

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/ManyToMany.pm
   DBIx-Class/0.08/trunk/t/66relationship.t
   DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/CD_to_Producer.pm
   DBIx-Class/0.08/trunk/t/lib/sqlite.sql
Log:
set_$rel accepts now a $link_vals hashref like add_to_$rel does

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm	2009-05-10 00:05:34 UTC (rev 6197)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/Base.pm	2009-05-10 15:37:16 UTC (rev 6198)
@@ -470,7 +470,7 @@
 
 =over 4
 
-=item Arguments: (\@hashrefs | \@objs)
+=item Arguments: (\@hashrefs | \@objs), $link_vals?
 
 =back
 
@@ -481,6 +481,10 @@
   $actor->set_roles(\@roles);
      # Replaces all of $actor's previous roles with the two named
 
+  $actor->set_roles(\@roles, { salary => 15_000_000 });
+     # Sets a column in the link table for all roles
+
+
 Replace all the related objects with the given reference to a list of
 objects. This does a C<delete> B<on the link table resultset> to remove the
 association between the current object and all related objects, then calls

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/ManyToMany.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/ManyToMany.pm	2009-05-10 00:05:34 UTC (rev 6197)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/ManyToMany.pm	2009-05-10 15:37:16 UTC (rev 6198)
@@ -103,7 +103,7 @@
       );
       my @to_set = (ref($_[0]) eq 'ARRAY' ? @{ $_[0] } : @_);
       $self->search_related($rel, {})->delete;
-      $self->$add_meth($_) for (@to_set);
+      $self->$add_meth($_, ref($_[1]) ? $_[1] : {}) for (@to_set);
     };
 
     my $remove_meth_name = join '::', $class, $remove_meth;

Modified: DBIx-Class/0.08/trunk/t/66relationship.t
===================================================================
--- DBIx-Class/0.08/trunk/t/66relationship.t	2009-05-10 00:05:34 UTC (rev 6197)
+++ DBIx-Class/0.08/trunk/t/66relationship.t	2009-05-10 15:37:16 UTC (rev 6198)
@@ -8,7 +8,7 @@
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 74;
+plan tests => 78;
 
 # has_a test
 my $cd = $schema->resultset("CD")->find(4);
@@ -189,6 +189,14 @@
 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' );
@@ -234,6 +242,7 @@
 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');

Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/CD_to_Producer.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/CD_to_Producer.pm	2009-05-10 00:05:34 UTC (rev 6197)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/CD_to_Producer.pm	2009-05-10 15:37:16 UTC (rev 6198)
@@ -7,6 +7,7 @@
 __PACKAGE__->add_columns(
   cd => { data_type => 'integer' },
   producer => { data_type => 'integer' },
+  attribute => { data_type => 'integer', is_nullable => 1 },
 );
 __PACKAGE__->set_primary_key(qw/cd producer/);
 

Modified: DBIx-Class/0.08/trunk/t/lib/sqlite.sql
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/sqlite.sql	2009-05-10 00:05:34 UTC (rev 6197)
+++ DBIx-Class/0.08/trunk/t/lib/sqlite.sql	2009-05-10 15:37:16 UTC (rev 6198)
@@ -108,6 +108,7 @@
 CREATE TABLE cd_to_producer (
   cd integer NOT NULL,
   producer integer NOT NULL,
+  attribute integer,
   PRIMARY KEY (cd, producer)
 );
 




More information about the Bast-commits mailing list