File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -600,8 +600,26 @@ protected function checkValidReverseAssociation(
600600 return false ;
601601 }
602602
603- $ reverseConditions = $ reverseAssociation ->getConditions ();
604- $ forwardConditions = $ forwardAssociation ->getConditions ();
603+ /**
604+ * Strip table aliases from the association conditions to prevent cases where a different alias causes
605+ * associations
606+ */
607+ $ stripAliasedConditions = function ($ conditions ) {
608+ if (!is_array ($ conditions )) {
609+ return $ conditions ;
610+ }
611+
612+ $ strippedConditions = [];
613+ foreach ($ conditions as $ field => $ condition ) {
614+ $ field = preg_replace ('/.*\.(.*)/ ' , '$1 ' , $ field );
615+ $ strippedConditions [$ field ] = $ condition ;
616+ }
617+
618+ return $ strippedConditions ;
619+ };
620+
621+ $ reverseConditions = $ stripAliasedConditions ($ reverseAssociation ->getConditions ());
622+ $ forwardConditions = $ stripAliasedConditions ($ forwardAssociation ->getConditions ());
605623
606624 if ($ forwardConditions !== $ reverseConditions ) {
607625 return false ;
You can’t perform that action at this time.
0 commit comments