notably on_connect* failures now properly abort the entire connect
- Fix corner case of stringify-only overloaded objects being used in
create()/populate()
+ - Fix several corner cases with Many2Many over custom relationships
- Fix t/52leaks.t failures on compilerless systems (RT#104429)
- Fix t/storage/quote_names.t failures on systems with specified Oracle
test credentials while missing the optional Math::Base36
"${add_meth} needs an object or hashref"
);
- my $link = $self->search_related_rs($rel)->new_result(
+ my $link = $self->new_related( $rel,
( @_ > 1 && ref $_[-1] eq 'HASH' )
? pop
: {}
;
$link->set_from_related($f_rel, $far_obj);
+
$link->insert();
return $far_obj;
@_ > 0 or $self->throw_exception(
"{$set_meth} needs a list of objects or hashrefs"
);
- my @to_set = (ref($_[0]) eq 'ARRAY' ? @{ $_[0] } : @_);
+
+ my $guard = $self->result_source->schema->storage->txn_scope_guard;
+
# 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);
+ $self->$add_meth($_, ref($_[1]) ? $_[1] : {})
+ for ( ref($_[0]) eq 'ARRAY' ? @{ $_[0] } : @_ );
+
+ $guard->commit;
};
my $remove_meth_name = join '::', $class, $remove_meth;
*$remove_meth_name = subname $remove_meth_name, sub {
my ($self, $obj) = @_;
+
$self->throw_exception("${remove_meth} needs an object")
unless blessed ($obj);
- my $rel_source = $self->search_related($rel)->result_source;
- my $cond = $rel_source->relationship_info($f_rel)->{cond};
- my ($link_cond, $crosstable) = $rel_source->_resolve_condition(
- $cond, $obj, $f_rel, $f_rel
- );
- $self->throw_exception(
- "Relationship '$rel' does not resolve to a join-free condition, "
- ."unable to use with the ManyToMany helper '$f_rel'"
- ) if $crosstable;
-
- $self->search_related($rel, $link_cond)->delete;
+ $self->search_related_rs($rel)->search_rs(
+ $obj->ident_condition( $f_rel ),
+ { join => $f_rel },
+ )->delete;
};
-
}
}
{ "$args->{foreign_alias}.artistid" => { -ident => "$args->{self_alias}.artist_id" },
"$args->{foreign_alias}.rank" => { '<' => 10 },
},
- $args->{self_result_object} && {
+ !$args->{self_result_object} ? () : {
"$args->{foreign_alias}.artistid" => $args->{self_result_object}->artist_id,
"$args->{foreign_alias}.rank" => { '<' => 10 },
- }
+ },
+ !$args->{foreign_values} ? () : {
+ "$args->{self_alias}.artist_id" => $args->{foreign_values}{artistid},
+ },
);
}
);
my $artwork = $schema->resultset('Artwork')->search({},{ order_by => 'cd_id' })->first;
-my @artists = $artwork->artists->all;
+my @artists = $artwork->artists->search({}, { order_by => 'artistid' } );
is(scalar @artists, 2, 'the two artists are associated');
my @artwork_artists = $artwork->artwork_to_artist->all;
1,
'Expected one m2m associated artist object via opaque custom cond + conditional far cond'
);
+
+ cmp_ok(
+ $artwork->${\"remove_from_$_"} ( $artists[1] ),
+ '==',
+ 0,
+ 'deletion action reports 0'
+ );
+
+ is (
+ scalar $artwork->all_artists_via_opaque_customcond->all,
+ 2,
+ 'Indeed nothing was removed'
+ );
+
+ cmp_ok(
+ $artwork->${\"remove_from_$_"} ( $artists[0] ),
+ '==',
+ 1,
+ 'Removal reports correct count'
+ );
+
+ is (
+ scalar $artwork->all_artists_via_opaque_customcond->all,
+ 1,
+ 'Indeed removed the matching artist'
+ );
+
+ $artwork->${\"set_$_"}([]);
+
+ is (
+ scalar $artwork->all_artists_via_opaque_customcond->all,
+ 0,
+ 'Everything removed via limited far cond'
+ );
+
+ # can't use the opaque one - need set_from_related to work
+ $artwork->set_artist_limited_rank( @artists );
+
+ {
+ local $TODO = 'Taking into account the relationship bridge condition is not likely to ever work... unless we get DQ hooked somehow';
+
+ is (
+ scalar $artwork->all_artists_via_opaque_customcond->all,
+ 1,
+ 'Re-Addition passed through only one of the artists'
+ );
+ }
+
+ throws_ok { $artwork->set_all_artists_via_opaque_customcond( \@artists ) }
+ qr/\QRelationship 'artwork_to_artist_via_opaque_customcond' on source 'Artwork' does not resolve to a join-free condition fragment/;
+
+ is (
+ scalar $artwork->all_artists_via_opaque_customcond->all,
+ 2,
+ 'Everything still there as expected'
+ );
}