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

beforeValidate() may cause problem when change status. #2

Open
sitawit opened this issue Jan 24, 2014 · 0 comments
Open

beforeValidate() may cause problem when change status. #2

sitawit opened this issue Jan 24, 2014 · 0 comments

Comments

@sitawit
Copy link

sitawit commented Jan 24, 2014

Issue

If you have other statuses as

  • "" (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • "0" (0 as a string)
  • FALSE

It will become a "default" status when you try to change status.

The Cause

The following function tries to set an empty status to be a "default" status.

    public function beforeValidate($event)
    {
        parent::beforeValidate($event);
        if ($this->owner->hasAttribute($this->statusAttribute) && empty($this->owner->{$this->statusAttribute})) {
            $this->owner->{$this->statusAttribute} = $this->defaultStatus;
        }
    }

So any value that makes empty() return true will cause the status become a "default".
However, this may not a big error but it could cause the confusion.

Possible solutions

  • Update read me file to warn people that don't use those value for other statuses than the default one.

or

  • Update the function to check the value properly
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

No branches or pull requests

1 participant