From: Nigel Metheringham Date: Wed, 24 Jun 2009 21:47:04 +0000 (+0100) Subject: Rework of set_$rel patch with less obfuscation X-Git-Tag: v0.08108~62 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=f1f9ee174a02240bae18bf358c25240ad5039b23 Rework of set_$rel patch with less obfuscation --- diff --git a/lib/DBIx/Class/Relationship/ManyToMany.pm b/lib/DBIx/Class/Relationship/ManyToMany.pm index a0edd92..2f47aab 100644 --- a/lib/DBIx/Class/Relationship/ManyToMany.pm +++ b/lib/DBIx/Class/Relationship/ManyToMany.pm @@ -107,7 +107,14 @@ EOW "{$set_meth} needs a list of objects or hashrefs" ); my @to_set = (ref($_[0]) eq 'ARRAY' ? @{ $_[0] } : @_); - $self->search_related( $rel, ($rel_attrs||{})->{where},($rel_attrs||{})->{where}?{join => $f_rel}:{} )->delete; + # if there is a where clause in the attributes, ensure we only delete + # rows that are within the where restriction + if ($rel_attrs && $rel_attrs->{where}) { + $self->search_related( $rel, $rel_attrs->{where},{join => $f_rel})->delete; + } else { + $self->search_related( $rel, {} )->delete; + } + # add in the set rel objects $self->$add_meth($_, ref($_[1]) ? $_[1] : {}) for (@to_set); };