Closed alexhouse closed 10 years ago
In fact, changing that line to:
if (false === $this->delete($object)) {
fixes the issue I'm seeing.
@GrahamCampbell this seems to be the same issue with ->save() with laravel being retarded and not returning booleans when it has already been deleted?
This issue has already been solved. Please see the previous issues on this repo.
Oh crap. I never implemented the custom stuff for the delete method. I forgot. Give me a min...
:P
Great success!
@scottrobertson We don't expect the save method to return a boolean in laravel btw. We expect an int for the number of rows modified. That's why I use an ==
comparison.
Ah right
@alexhouse Here's the new usage then:
First of all, you no longer will be calling:
Facade::setDeleteMethod('forceDelete');
Now you can call:
Facade::setCusomDeleter(function ($object) {
$object->forceDelete();
return true;
})
This will now call force delete on all your objects, and will return true to satisfy our quick checks.
//cc @scottrobertson
You can install the new version with:
{
"require-dev": {
"league/factory-muffin": "2.1.*@dev"
}
}
Perfect, thanks @GrahamCampbell !
Been talking to @scottrobertson about this, not entirely sure why this is happening, but when setting the delete method to
forceDelete
using:I'm getting some odd errors. Although
Factory::deleteSaved()
does actually delete the saved models, it still ends up throwing exceptions:We could not delete the model of type: 'User'.
Stack trace:
I'm wondering if it has something to do with how you check for return value from firing the delete method here: https://github.com/thephpleague/factory-muffin/blob/d81fde9e8437c9ed74fa6d7137a2cb639767e515/src/Factory.php#L461
forceDelete
doesn't actually return a value, so perhaps this is why the exception gets thrown, despite the fact the model actually gets deleted?