22
33namespace Kirschbaum \PowerJoins \Mixins ;
44
5+ use Stringable ;
6+ use Illuminate \Support \Str ;
57use Kirschbaum \PowerJoins \StaticCache ;
68use Kirschbaum \PowerJoins \PowerJoinClause ;
79use Kirschbaum \PowerJoins \Tests \Models \Post ;
@@ -256,8 +258,8 @@ protected function performJoinForEloquentPowerJoinsForMorphTo()
256258 "{$ modelInstance ->getTable ()}. {$ modelInstance ->getKeyName ()}"
257259 )->where ("{$ this ->getModel ()->getTable ()}. {$ this ->getMorphType ()}" , '= ' , $ modelInstance ->getMorphClass ());
258260
259- if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ this -> query -> getModel () )) {
260- $ join ->whereNull ($ this -> query -> getModel () ->getQualifiedDeletedAtColumn ());
261+ if ($ disableExtraConditions === false && $ this ->usesSoftDeletes ($ modelInstance )) {
262+ $ join ->whereNull ($ modelInstance ->getQualifiedDeletedAtColumn ());
261263 }
262264
263265 if ($ disableExtraConditions === false ) {
@@ -267,7 +269,7 @@ protected function performJoinForEloquentPowerJoinsForMorphTo()
267269 if ($ callback && is_callable ($ callback )) {
268270 $ callback ($ join );
269271 }
270- }, $ this -> getModel () );
272+ }, $ modelInstance );
271273
272274 return $ this ;
273275 };
@@ -485,7 +487,13 @@ public function applyNestedCondition()
485487 public function shouldNotApplyExtraCondition ()
486488 {
487489 return function ($ condition ) {
488- $ key = $ this ->getPowerJoinExistenceCompareKey ();
490+ if (isset ($ condition ['column ' ]) && Str::endsWith ($ condition ['column ' ], '. ' )) {
491+ return true ;
492+ }
493+
494+ if (! $ key = $ this ->getPowerJoinExistenceCompareKey ()) {
495+ return true ;
496+ }
489497
490498 if (isset ($ condition ['query ' ])) {
491499 return false ;
@@ -502,6 +510,10 @@ public function shouldNotApplyExtraCondition()
502510 public function getPowerJoinExistenceCompareKey ()
503511 {
504512 return function () {
513+ if ($ this instanceof MorphTo) {
514+ return [$ this ->getMorphType (), $ this ->getForeignKeyName ()];
515+ }
516+
505517 if ($ this instanceof BelongsTo) {
506518 return $ this ->getQualifiedOwnerKeyName ();
507519 }
0 commit comments