Skip to content

[9.x] Add whereNotMorphedTo, orWhereNotMorphedTo#42264

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
patrickomeara:9.x
May 5, 2022
Merged

[9.x] Add whereNotMorphedTo, orWhereNotMorphedTo#42264
taylorotwell merged 1 commit into
laravel:9.xfrom
patrickomeara:9.x

Conversation

@patrickomeara

Copy link
Copy Markdown
Contributor

This PR adds the inverse of whereMorphedTo, and orWhereMorphedTo.

I've also added tests for new methods and missing test for orWhereMorphedTo.

The following code could be extracted to a static method on Relation as it's now duplicated.

$morphMap = Relation::morphMap();

if (! empty($morphMap) && in_array($model, $morphMap)) {
    $model = array_search($model, $morphMap, true);
}

I wasn't sure on the terminology from the morph map, are they called "keys", or "morph type values", something else? :D

Then I noticed there was already a getMorphedModel static method

public static function getMorphedModel($alias)
{
    return static::$morphMap[$alias] ?? null;
}

Anyway I'm open to suggestion on the naming if this code should be extracted.

* this adds the inverse of whereMorphedTo, and orWhereMorphedTo
* added tests for new methods and missing test for orWhereMorphedTo
@patrickomeara patrickomeara changed the title Add whereNotMorphedTo, orWhereNotMorphedTo [9.x] Add whereNotMorphedTo, orWhereNotMorphedTo May 5, 2022
@taylorotwell taylorotwell merged commit e742118 into laravel:9.x May 5, 2022
@yngc0der

Copy link
Copy Markdown

Thats does not return values if column "model_type" is equal to NULL
generated sql: "select * from table where not model_type = ?"
maybe expected: "select * from table where not model_type <=> ?" (with null-safe)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants