@@ -631,39 +631,15 @@ your storage until you call L<DBIx::Class::Row/insert> on it.
631
631
=cut
632
632
633
633
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 } );
667
643
}
668
644
669
645
=head2 create_related
@@ -805,37 +781,13 @@ set them in the storage.
805
781
sub set_from_related {
806
782
my ($self , $rel , $f_obj ) = @_ ;
807
783
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 } );
839
791
840
792
return 1;
841
793
}
0 commit comments