Commit a5c4a0eb by Alexander Makarov

Adjusted BaseActiveRecord code for better noSQL compatibility

parent ed041f7a
...@@ -1297,8 +1297,6 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -1297,8 +1297,6 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
public function unlinkAll($name, $delete = false) public function unlinkAll($name, $delete = false)
{ {
$relation = $this->getRelation($name); $relation = $this->getRelation($name);
/** @var Command $command */
$command = static::getDb()->createCommand();
$columns = []; $columns = [];
$condition = []; $condition = [];
if (empty($relation->via)) { if (empty($relation->via)) {
...@@ -1308,18 +1306,22 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -1308,18 +1306,22 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
foreach ($relation->link as $a => $b) { foreach ($relation->link as $a => $b) {
$condition[$a] = $this->$b; $condition[$a] = $this->$b;
} }
$command->delete($viaClass::tableName(), $condition)->execute(); $viaClass::deleteAll($condition);
} else { } else {
foreach ($relation->link as $a => $b) { foreach ($relation->link as $a => $b) {
$columns[$a] = null; $columns[$a] = null;
$condition[$a] = $this->$b; $condition[$a] = $this->$b;
} }
$command->update($viaClass::tableName(), $columns, $condition)->execute(); $viaClass::updateAll($columns, $condition);
} }
} else { } else {
$viaTable = $viaTable = reset($relation->via->from); $viaTable = reset($relation->via->from);
/** @var ActiveQuery $viaRelation */ /** @var ActiveQuery $viaRelation */
$viaRelation = $relation->via; $viaRelation = $relation->via;
/** @var Command $command */
$command = static::getDb()->createCommand();
if ($delete) { if ($delete) {
foreach ($viaRelation->link as $a => $b) { foreach ($viaRelation->link as $a => $b) {
$condition[$a] = $this->$b; $condition[$a] = $this->$b;
......
...@@ -45,6 +45,10 @@ trait ActiveRecordTestTrait ...@@ -45,6 +45,10 @@ trait ActiveRecordTestTrait
*/ */
abstract public function getItemClass(); abstract public function getItemClass();
abstract public function getOrderWithNullFKClass();
abstract public function getOrderItemWithNullFKmClass();
/** /**
* can be overridden to do things after save() * can be overridden to do things after save()
*/ */
...@@ -724,7 +728,7 @@ trait ActiveRecordTestTrait ...@@ -724,7 +728,7 @@ trait ActiveRecordTestTrait
public function testUnlinkAll() public function testUnlinkAll()
{ {
/** @var \yii\db\ActiveRecordInterface $customerClass */ /** @var \yii\db\ActiveRecordInterface $customewdfsdfdfsfd
$customerClass = $this->getCustomerClass(); $customerClass = $this->getCustomerClass();
/** @var \yii\db\ActiveRecordInterface $orderClass */ /** @var \yii\db\ActiveRecordInterface $orderClass */
$orderClass = $this->getOrderClass(); $orderClass = $this->getOrderClass();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment