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.5] Fix Database Collection Fresh for deleted records #21159

Merged
merged 3 commits into from
Sep 13, 2017

Conversation

deleugpn
Copy link
Contributor

@deleugpn deleugpn commented Sep 13, 2017

When requesting a fresh() database collection, if any item has been deleted in a way that the collection itself is not aware, fresh() will fail with undefined offset

1) Illuminate\Tests\Integration\Database\EloquentCollectionFreshTest::test_eloquent_collection_fresh
ErrorException: Undefined offset: 1

/var/www/forks/framework/src/Illuminate/Database/Eloquent/Collection.php:162
/var/www/forks/framework/src/Illuminate/Support/Collection.php:833
/var/www/forks/framework/src/Illuminate/Database/Eloquent/Collection.php:134
/var/www/forks/framework/src/Illuminate/Database/Eloquent/Collection.php:163
/var/www/forks/framework/tests/Integration/Database/EloquentCollectionFreshTest.php:53

The problem is because $model->exists will only return false if we use the same collection to delete the records. When deleting the records without the collection's knowledge, $model->exists will still return true, but $freshModels will not have that record.

@deleugpn
Copy link
Contributor Author

I really needed this fix on 5.4

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.

None yet

2 participants