Skip to content

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.

2 participants