我有一个表products和一些表按product\u id与其连接。当从product表中删除产品时,我想从所有其他表中删除此product\u id的所有行。现在怎样才能方便地做呢?我尝试如下:
$productTable = [
'related_products',
'quantities',
'products_tags',
'products_settings',
'products_details',
'categories_products',
];
$tableObj = TableRegistry::get('Products');
$query = $tableObj->query();
$result = $query->deleteAll()
->contain($productTable)
->where(['store_id' => $storeId])
->execute();
1条答案
按热度按时间hs1ihplo1#
在cakephp中,有一个从其他表中删除相关数据的依赖属性。
当依赖项设置为true时,实体被删除,关联的模型记录也被删除。在本例中,我们将其设置为true,这样删除用户也将删除其关联的地址。
要使用它,只需创建
association
并添加dependent
是的。例如蛋糕->关联-将表链接在一起