我试图删除与其他实体 (B) 有关系的实体 (A),该实体具有针对实体 A 配置的删除级联。删除实体 A 类型的多个实体且中间有刷新时,将恢复已删除的实体。
例如,在以下情况下:
$orm->remove($actionButton);
$orm->flush();
$orm->remove($actionButton2);
$orm->flush();
这将导致以下查询:
"START TRANSACTION"
DELETE FROM action_button WHERE action_button_id = ?
array (size=1)
0 => int 6
"COMMIT"
"START TRANSACTION"
INSERT INTO action_button (action_button_color, media_id) VALUES (?, ?)
array (size=2)
1 => string '#000' (length=4)
2 => null
DELETE FROM action_button WHERE action_button_id = ?
array (size=1)
0 => int 7
"COMMIT"
具有以下实体:
/**
* ActionButtonLanguage
*
* @ORMTable(name="action_button_language", indexes={@ORMIndex(name="language_id", columns={"language_id"})})
* @ORMEntity
*/
class ActionButtonLanguage
{
/**
* @var Education
*
* @ORMId
* @ORMManyToOne(targetEntity="ActionButton", inversedBy="actionButtonLanguages", cascade={"persist"})
* @ORMJoinColumns({
* @ORMJoinColumn(name="action_button_id", referencedColumnName="action_button_id", onDelete="CASCADE")
* })
*/
private $actionButton;
....
}
/**
* ActionButton
*
* @ORMTable(name="action_button")
* @ORMEntity
*/
class ActionButton
{
/**
* @var DoctrineCommonCollectionsCollection
*
* @ORMOneToMany(targetEntity="ActionButtonLanguage", mappedBy="actionButton", cascade={"persist"})
*/
private $actionButtonLanguages;
....
}
为什么要还原这些实体,如何防止它们在两者之间刷新时还原?
编辑:
测试代码:
//Test area
$language = new Language();
$language->setLanguageName('EN');
$actionButton = new ActionButton();
$actionButton->setActionButtonColor('#000');
$orm->persist($actionButton);
$actionButtonLanguage = new ActionButtonLanguage();
$actionButtonLanguage->setActionButtonName('test');
$actionButtonLanguage->setActionButton($actionButton);
$actionButtonLanguage->setLanguage($language);
$orm->persist($actionButtonLanguage);
$actionButton2 = new ActionButton();
$actionButton2->setActionButtonColor('#000');
$orm->persist($actionButton2);
$actionButtonLanguage2 = new ActionButtonLanguage();
$actionButtonLanguage2->setActionButtonName('test');
$actionButtonLanguage2->setActionButton($actionButton2);
$actionButtonLanguage2->setLanguage($language);
$orm->persist($actionButtonLanguage2);
$orm->flush();
$ormHelper = new CMSincludesdatabaseORMHelper();
$ormHelper->enableLogging(1);
$orm->remove($actionButton);
$orm->flush();
$orm->remove($actionButton2);
$orm->flush();
这些实体恢复是因为在刷新操作期间出现问题。也许级联删除失败,或者另一个联接阻止了该操作。您确定已在数据库架构中生成级联吗?