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

Fix scope with state zero #89

Merged
merged 1 commit into from
Jun 23, 2020
Merged

Conversation

mvdnbrk
Copy link
Contributor

@mvdnbrk mvdnbrk commented Jun 19, 2020

I had two states, let's say Draft and Published with values of 0 and 1:

class Draft extends PostState
{
    public static $name = 0;
}

// and

class Published extends PostState
{
    public static $name = 1;
}

Now when you scope the model like so:

Post::whereState('state', Draft::class)

This will return the published ones instead of the expected posts with state Draft.
This is because of the $name property in the Draft state is set to 0.

In this scenario the state class is not resolved properly in the resolveStateClass method.

This PR aims to solve this issue.
Added a test as well.

@brendt
Copy link
Contributor

brendt commented Jun 23, 2020

Thanks!

@brendt brendt merged commit cba9fd4 into spatie:master Jun 23, 2020
@brendt
Copy link
Contributor

brendt commented Jun 23, 2020

@mvdnbrk mvdnbrk deleted the fix-scope-state-with-zero branch June 23, 2020 11:46
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.

2 participants