update remove by Query
This commit is contained in:
@@ -5,7 +5,6 @@ namespace devgroup\arangodb;
|
||||
use Yii;
|
||||
use yii\base\ArrayableTrait;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\Model;
|
||||
use yii\db\ActiveQueryInterface;
|
||||
use yii\db\BaseActiveRecord;
|
||||
use yii\db\StaleObjectException;
|
||||
@@ -113,11 +112,11 @@ abstract class ActiveRecord extends BaseActiveRecord
|
||||
* }
|
||||
*
|
||||
* // Use andWhere()/orWhere() to apply the default condition
|
||||
* // SELECT FROM customer WHERE `deleted`=:deleted AND age>30
|
||||
* // FOR customer IN customer FILTER customer.deleted=:deleted AND customer.age>30 RETURN customer
|
||||
* $customers = Customer::find()->andWhere('age>30')->all();
|
||||
*
|
||||
* // Use where() to ignore the default condition
|
||||
* // SELECT FROM customer WHERE age>30
|
||||
* // FOR customer IN customer FILTER customer.age>30 RETURN customer
|
||||
* $customers = Customer::find()->where('age>30')->all();
|
||||
*
|
||||
* @return ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.
|
||||
@@ -235,10 +234,12 @@ abstract class ActiveRecord extends BaseActiveRecord
|
||||
$this->setAttribute($key, $attribute);
|
||||
}
|
||||
|
||||
$rows = static::getDb()->getDocumentHandler()->updateById(
|
||||
$rows = (new Query())->update(
|
||||
static::collectionName(),
|
||||
$this->getOldAttribute('_key'),
|
||||
Document::createFromArray($values)
|
||||
$values,
|
||||
[
|
||||
'_key' => $this->getOldAttribute('_key'),
|
||||
]
|
||||
);
|
||||
|
||||
if ($lock !== null && !$rows) {
|
||||
@@ -300,20 +301,7 @@ abstract class ActiveRecord extends BaseActiveRecord
|
||||
*/
|
||||
public static function updateAll($attributes, $condition = [])
|
||||
{
|
||||
$docs = static::findAll($condition);
|
||||
|
||||
$count = 0;
|
||||
foreach ($docs as $doc) {
|
||||
foreach ($attributes as $key => $attribute) {
|
||||
$doc->setAttribute($key, $attribute);
|
||||
$doc->document->set($key, $attribute);
|
||||
}
|
||||
if (static::getDb()->getDocumentHandler()->update($doc->document)) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
return (new Query())->update(static::collectionName(), $attributes, $condition);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -331,19 +319,9 @@ abstract class ActiveRecord extends BaseActiveRecord
|
||||
* An empty condition will match all records.
|
||||
* @return integer the number of rows deleted
|
||||
*/
|
||||
public static function deleteAll($condition = null)
|
||||
public static function deleteAll($condition = [])
|
||||
{
|
||||
/** @var Document[] $docs */
|
||||
$records = static::findAll($condition);
|
||||
|
||||
$count = 0;
|
||||
foreach ($records as $record) {
|
||||
if (static::getDb()->getDocumentHandler()->remove($record->document)) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
return (new Query())->remove(static::collectionName(), $condition);
|
||||
}
|
||||
|
||||
public static function truncate()
|
||||
@@ -410,7 +388,7 @@ abstract class ActiveRecord extends BaseActiveRecord
|
||||
if ($lock !== null) {
|
||||
$condition[$lock] = $this->$lock;
|
||||
}
|
||||
$result = static::getDb()->getDocumentHandler()->removeById(static::collectionName(), $condition);
|
||||
$result = (new Query())->remove(static::collectionName(), $condition);
|
||||
if ($lock !== null && !$result) {
|
||||
throw new StaleObjectException('The object being deleted is outdated.');
|
||||
}
|
||||
|
Reference in New Issue
Block a user