From: Nigel Metheringham Date: Wed, 24 Jun 2009 21:27:58 +0000 (+0100) Subject: Fixed set_$rel with where restriction deleting rows outside the restriction X-Git-Tag: v0.08108~63 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d2d82857c6643eee65dd3642f0109c064766c90a;p=dbsrgits%2FDBIx-Class.git Fixed set_$rel with where restriction deleting rows outside the restriction --- diff --git a/Changes b/Changes index 5ebf0e7..074cbf0 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,8 @@ Revision history for DBIx::Class which in turn returns a single count value - make_column_dirty() now overwrites the deflated value with an inflated one if such exists + - Fixed set_$rel with where restriction deleting rows outside + the restriction 0.08107 2009-06-14 08:21:00 (UTC) - Fix serialization regression introduced in 0.08103 (affects diff --git a/lib/DBIx/Class/Relationship/ManyToMany.pm b/lib/DBIx/Class/Relationship/ManyToMany.pm index bab7bb1..a0edd92 100644 --- a/lib/DBIx/Class/Relationship/ManyToMany.pm +++ b/lib/DBIx/Class/Relationship/ManyToMany.pm @@ -107,7 +107,7 @@ EOW "{$set_meth} needs a list of objects or hashrefs" ); my @to_set = (ref($_[0]) eq 'ARRAY' ? @{ $_[0] } : @_); - $self->search_related($rel, {})->delete; + $self->search_related( $rel, ($rel_attrs||{})->{where},($rel_attrs||{})->{where}?{join => $f_rel}:{} )->delete; $self->$add_meth($_, ref($_[1]) ? $_[1] : {}) for (@to_set); }; diff --git a/t/46where_attribute.t b/t/46where_attribute.t index 6ed3125..1c03591 100644 --- a/t/46where_attribute.t +++ b/t/46where_attribute.t @@ -7,7 +7,7 @@ use lib qw(t/lib); use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 16; +plan tests => 19; # select from a class with resultset_attributes my $resultset = $schema->resultset('BooksInLibrary'); @@ -72,3 +72,14 @@ eval {$collection->add_to_objects({ value => "Wheel", type => "round" })}; if ($@) { print $@ } ok( !$@, 'many_to_many add_to_$rel($hash) did not throw'); is($round_objects->count, $round_count+1, 'many_to_many add_to_$rel($hash) count correct'); + +# test set_$rel +$round_count = $round_objects->count(); +$pointy_count = $pointy_objects->count(); +my @all_pointy_objects = $pointy_objects->all; +# doing a set on pointy objects with its current set should not change any counts +eval {$collection->set_pointy_objects(\@all_pointy_objects)}; +if ($@) { print $@ } +ok( !$@, 'many_to_many set_$rel(\@objects) did not throw'); +is($pointy_objects->count, $pointy_count, 'many_to_many set_$rel($hash) count correct'); +is($round_objects->count, $round_count, 'many_to_many set_$rel($hash) other rel count correct');