Skip to content

Commit 83a6b24

Browse files
committed
Another heavy refactor of the rel resolver prototype (sequel to 03f6d1f)
Change the return value of _resolve_relationship_condition to a 3-value hash, with a lot of the safety logic consolidated within that method. The best way to gauge the significance of the changes is to look at the diff of lib/DBIx/Class/Relationship/Base.pm Also stop returning the "noncondition-columns" in the _resolve_condition compa-shim. The information was only used by the code removed from ::Relationship::Base, and is rather new with no evidence of use within CPAN/DarkPAN. It can be easily added back if necessary.
1 parent ee33377 commit 83a6b24

File tree

3 files changed

+155
-145
lines changed

3 files changed

+155
-145
lines changed

lib/DBIx/Class/Relationship/Base.pm

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -631,39 +631,15 @@ your storage until you call L<DBIx::Class::Row/insert> on it.
631631
=cut
632632

633633
sub new_related {
634-
my ($self, $rel, $values) = @_;
635-
636-
# FIXME - this is a bad position for this (also an identical copy in
637-
# set_from_related), but I have no saner way to hook, and I absolutely
638-
# want this to throw at least for coderefs, instead of the "insert a NULL
639-
# when it gets hard" insanity --ribasushi
640-
#
641-
# sanity check - currently throw when a complex coderef rel is encountered
642-
# FIXME - should THROW MOAR!
643-
644-
my $rsrc = $self->result_source;
645-
my $rel_info = $rsrc->relationship_info($rel)
646-
or $self->throw_exception( "No such relationship '$rel'" );
647-
my (undef, $crosstable, $nonequality_foreign_columns) = $rsrc->_resolve_condition (
648-
$rel_info->{cond}, $rel, $self, $rel
649-
);
650-
651-
$self->throw_exception("Relationship '$rel' does not resolve to a join-free condition fragment")
652-
if $crosstable;
653-
654-
if (
655-
$nonequality_foreign_columns
656-
and
657-
my @unspecified_rel_condition_chunks = grep { ! exists $values->{$_} } @$nonequality_foreign_columns
658-
) {
659-
$self->throw_exception(sprintf (
660-
"Custom relationship '%s' not definitive - returns conditions instead of values for column(s): %s",
661-
$rel,
662-
map { "'$_'" } @unspecified_rel_condition_chunks
663-
));
664-
}
665-
666-
return $self->search_related($rel)->new_result($values);
634+
my ($self, $rel, $data) = @_;
635+
636+
return $self->search_related($rel)->new_result( $self->result_source->_resolve_relationship_condition (
637+
infer_values_based_on => $data,
638+
rel_name => $rel,
639+
self_resultobj => $self,
640+
foreign_alias => $rel,
641+
self_alias => 'me',
642+
)->{inferred_values} );
667643
}
668644

669645
=head2 create_related
@@ -805,37 +781,13 @@ set them in the storage.
805781
sub set_from_related {
806782
my ($self, $rel, $f_obj) = @_;
807783

808-
my $rsrc = $self->result_source;
809-
my $rel_info = $rsrc->relationship_info($rel)
810-
or $self->throw_exception( "No such relationship '$rel'" );
811-
812-
if (defined $f_obj) {
813-
my $f_class = $rel_info->{class};
814-
$self->throw_exception( "Object '$f_obj' isn't a ".$f_class )
815-
unless blessed $f_obj and $f_obj->isa($f_class);
816-
}
817-
818-
819-
# FIXME - this is a bad position for this (also an identical copy in
820-
# new_related), but I have no saner way to hook, and I absolutely
821-
# want this to throw at least for coderefs, instead of the "insert a NULL
822-
# when it gets hard" insanity --ribasushi
823-
#
824-
# sanity check - currently throw when a complex coderef rel is encountered
825-
# FIXME - should THROW MOAR!
826-
my ($cond, $crosstable, $nonequality_foreign_columns) = $rsrc->_resolve_condition (
827-
$rel_info->{cond}, $f_obj, $rel, $rel
828-
);
829-
$self->throw_exception("Relationship '$rel' does not resolve to a join-free condition fragment")
830-
if $crosstable;
831-
832-
$self->throw_exception(sprintf (
833-
"Custom relationship '%s' not definitive - returns conditions instead of values for column(s): %s",
834-
$rel,
835-
map { "'$_'" } @$nonequality_foreign_columns
836-
)) if $nonequality_foreign_columns;
837-
838-
$self->set_columns($cond);
784+
$self->set_columns( $self->result_source->_resolve_relationship_condition (
785+
infer_values_based_on => {},
786+
rel_name => $rel,
787+
foreign_resultobj => $f_obj,
788+
foreign_alias => $rel,
789+
self_alias => 'me',
790+
)->{inferred_values} );
839791

840792
return 1;
841793
}

0 commit comments

Comments
 (0)