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

[5.3] Remove the condition from updateOrInsert since it's added already #15540

Merged
merged 2 commits into from
Sep 21, 2016
Merged

[5.3] Remove the condition from updateOrInsert since it's added already #15540

merged 2 commits into from
Sep 21, 2016

Conversation

themsaid
Copy link
Member

@themsaid themsaid commented Sep 21, 2016

public function updateOrInsert(array $attributes, array $values = [])
{
    if (! $this->where($attributes)->exists()) {
        return $this->insert(array_merge($attributes, $values));
    }

    return (bool) $this->where($attributes)->take(1)->update($values);
}

Calling $this->where($attributes)->exists() adds the conditions already, adding another where() while making an update results a query like this:

update `users` set `name` = ? where (`name` = ?) and (`name` = ?) limit 1

@taylorotwell
Copy link
Member

Looks like test failed :)

@themsaid
Copy link
Member Author

@taylorotwell Oops, sorry about that. Fixed the failing test.

@taylorotwell taylorotwell merged commit d145a84 into laravel:5.3 Sep 21, 2016
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