mitchellvanw / laravel-doctrine

NO LONGER MAINTAINED! A Doctrine 2 implementation that melts with Laravel
MIT License
187 stars 74 forks source link

Are softDeletes working? #112

Closed guiwoda closed 9 years ago

guiwoda commented 9 years ago

I had to change the way SoftDeletableListener applies changes to the SoftDeletable entity, because it wasn't setting the deleted_at timestamp and it was actually deleting it!

// All $entity methods used here are required in the SoftDeletable interface
if ($entity instanceof SoftDeletable)
{
    if ($entity->isDeleted())
    {
        continue;
    }

    $entity->markAsDeleted();
    $entityManager->persist($entity);

    $now = $entity->getDeletedAt();

    $unitOfWork->propertyChanged($entity, 'deletedAt', null, $now);
    $unitOfWork->scheduleExtraUpdate(
        $entity,
        [
            'deletedAt' => [null, $now]
        ]
    );
}
kirkbushell commented 9 years ago

You cannot check to see if an entity is an instance of based on traits - you have to use the class_uses() function to do those checks - so your check would be failing, which is why it's not working.

guiwoda commented 9 years ago

Yeah, I actually have an interface as well as the Trait. Anyway, I'll see if I can do a test to verify it.