Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add whereNotMorphedTo, orWhereNotMorphedTo #42264

Merged
merged 1 commit into from
May 5, 2022
Merged

[9.x] Add whereNotMorphedTo, orWhereNotMorphedTo #42264

merged 1 commit into from
May 5, 2022

Conversation

patrickomeara
Copy link
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

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