When I delete an entity which have a belongsToMany association ORM does not delete the joint table data. (Cake v 4.1.7)
$this->SpaceObjects->deleteAll(['type' => 1]);
the setup looks like this:
class SpaceObjectsTable extends Table
{
public function initialize(array $config): void
{
...
$this->belongsToMany('Assets', [
'foreignKey' => 'space_object_id',
'targetForeignKey' => 'asset_id',
'joinTable' => 'assets_space_objects'
]);
...
class AssetsTable extends Table
{
public function initialize(array $config): void
{
...
$this->belongsToMany('SpaceObjects', [
'foreignKey' => 'asset_id',
'targetForeignKey' => 'space_object_id',
'joinTable' => 'assets_space_objects',
]);
...
DB Table “assets_space_objects”: Id, space_object_id, asset_id
I added Foreign key constraints in the DB and it works, but it bothers me why ORM is not working the way it says in the docs.
What am I doing wrong?