Yii2在未提交事务中更正行为activerecord关系
将应用程序从yii 2.0.2升级到yii 2.0.35后,在未提交事务中通过连接表获取关系时出现问题 示例3具有活动记录“A B C”的表 AR“A”通过AR“B”与AR“C”有关联 这里有一个示例代码Yii2在未提交事务中更正行为activerecord关系,activerecord,yii2,transactions,Activerecord,Yii2,Transactions,将应用程序从yii 2.0.2升级到yii 2.0.35后,在未提交事务中通过连接表获取关系时出现问题 示例3具有活动记录“A B C”的表 AR“A”通过AR“B”与AR“C”有关联 这里有一个示例代码 $dbTransaction = A::getDb()->beginTransaction(); try { // record in junction table "B" not exist $c = $a->
$dbTransaction = A::getDb()->beginTransaction();
try {
// record in junction table "B" not exist
$c = $a->getC(); // null in both versions because B record not exist
$c->link('a', $a, ['is_set' => 1]);
// record in juction table "B" created
// from this moment different behavior
$c = $a->getC(); // 2.0.2 return instance of C
// 2.0.35 return null
$dbTransaction->commit();
$c = $a->getC() instance of C in both versions
} catch (Exception $e) {
$dbTransaction->rollBack();
}
我在变更日志或升级指南中没有发现差异。哪一种行为是正确的?
有没有可能使yii2.0.35的行为与2.0.2相同
$dbTransaction = A::getDb()->beginTransaction();
try {
// record in junction table "B" not exist
$c = $a->getC(); // null in both versions because B record not exist
$c->link('a', $a, ['is_set' => 1]);
// record in juction table "B" created
// from this moment different behavior
$c = $a->getC(); // 2.0.2 return instance of C
// 2.0.35 return null
$dbTransaction->commit();
$c = $a->getC() instance of C in both versions
} catch (Exception $e) {
$dbTransaction->rollBack();
}