-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
updateOrCreate -> createOrFirst doesn't work as expected #2945
Comments
Thanks for the report. |
After investigation, This is inconsistent with how SQL works because SQL databases will generate a value with a request like this: Can you modify your code like this: $id = $request->get('id'); // null is the default value
if ($id) {
$model = Model::updateOrCreate(['_id' => $id], $data);
} else {
$model = Model::create($data);
} |
Closing as this is the expected behavior for MongoDB. |
Description:
Steps to reproduce
Model::updateOrCreate(['_id' => $id], $data);
Expected behaviour
A new record should be created with the given data and a generated _id.
Actual behaviour
It queries the first record from the collection and updates it.
This works fine when using the package 4.0 because the createOrFirst is not overriden there in the Mongo Builder class
The text was updated successfully, but these errors were encountered: