Closed matiux closed 9 years ago
Yeah the soft delete trait doesn't deal with any cascading, it only sets the deleted_at field, as you've pointed out. I think this is something we could definitely support if you wanted to put something together, otherwise I feel it may not make it in for a while.
So, for now, I have to soft deleting all entities manually, right?
Well, actually, cascading soft delete works for me, when cascading from the OneToMany side:
**
* @ORM\Entity
* @ORM\Table(name = "device")
*/
class Device {
use Timestamps;
use SoftDeletes;
/**
* @ORM\OneToMany(targetEntity="Port",
* mappedBy = "device", cascade = {"persist", "remove", "merge", "detach"})
*/
protected $ports;
...
}
/**
* @ORM\Entity
* @ORM\Table(name = "port")
*/
class Port {
use Timestamps;
use SoftDeletes;
/**
* @ORM\ManyToOne(targetEntity = "Device", inversedBy="ports")
* @ORM\JoinColumn(referencedColumnName = "id")
*/
protected $device;
...
}
Then removing:
$this->em->remove($device);
Cascades soft deletes like this:
UPDATE port SET deleted_at = '2014-10-14 13:09:30' WHERE id = 322352;
UPDATE device SET deleted_at = '2014-10-14 13:09:30' WHERE id = 79219;
OK, I have decided to remove the foreign key to handle delete cascade with mysql and I have left only the cascade option in model property. So, now work correctly. Thanks for your suggestion and sorry for my english
@matiux Glad it works and @hhjcz thanks for clarifying.
Closing.
So no cascading with soft deletes?
@interludic this project is no longer maintained.
Hi guys and sorry for my bad English. I have create 2 entities, user and user_data, binded between them to "user_data_id" in user model. This is the code in user model:
And this is the code in user user_data model:
So, when I delete a record in user_data table from phpmyadmin, the related records in user table will be deleted. But when I perform deleting from code, "soft delete" method, updates the deleted_at column fine, but not also in related tables:
Some suggestion?