Исправления

This commit is contained in:
Arsen Mirzaev Tatyano-Muradovich 2021-03-29 10:20:46 +10:00
parent a7abed56d6
commit 7a6e6fbada
2 changed files with 34 additions and 11 deletions

View File

@ -107,7 +107,7 @@ abstract class ActiveRecord extends BaseActiveRecord
{
/** @var ActiveQuery $query */
$query = Yii::createObject(ActiveQuery::class, [get_called_class()]);
$query->collection(static::collectionName())->select(static::collectionName());
$query->in(static::collectionName())->select(static::collectionName());
return $query;
}
@ -170,6 +170,7 @@ abstract class ActiveRecord extends BaseActiveRecord
if ($runValidation && !$this->validate($attributes)) {
return false;
}
$result = $this->insertInternal($attributes, $options);
return $result;
@ -189,7 +190,9 @@ abstract class ActiveRecord extends BaseActiveRecord
}
$newId = static::getDb()->getDocumentHandler()->save(static::collectionName(), $values);
static::populateRecord($this, static::getDb()->getDocument(static::collectionName(), $newId));
$this->setIsNewRecord(false);
$changedAttributes = array_fill_keys(array_keys($values), null);
@ -217,8 +220,11 @@ abstract class ActiveRecord extends BaseActiveRecord
$this->afterSave(false, $values);
return 0;
}
$condition = $this->getOldPrimaryKey(true);
$lock = $this->optimisticLock();
if ($lock !== null) {
if (!isset($values[$lock])) {
$values[$lock] = $this->$lock + 1;
@ -230,12 +236,17 @@ abstract class ActiveRecord extends BaseActiveRecord
$this->setAttribute($key, $attribute);
}
$rows = (new Query())->options($options)->update(
static::collectionName(),
$rows = (new Query())
->options($options)
->in(static::collectionName())
->where(['_key' => $this->getOldAttribute('_key')])
->update(
array_merge(
$values,
[
'_key' => $this->getOldAttribute('_key'),
]
)
);
if ($lock !== null && !$rows) {
@ -298,7 +309,7 @@ abstract class ActiveRecord extends BaseActiveRecord
*/
public static function updateAll($attributes, $condition = [], $options = [])
{
return (new Query())->options($options)->update(static::collectionName(), $attributes, $condition);
return (new Query())->options($options)->in(static::collectionName())->update($attributes, $condition);
}
/**
@ -319,7 +330,7 @@ abstract class ActiveRecord extends BaseActiveRecord
*/
public static function deleteAll($condition = [], $options = [])
{
return (new Query())->options($options)->remove(static::collectionName(), $condition);
return (new Query())->options($options)->in(static::collectionName())->remove($condition);
}
public static function truncate()
@ -369,6 +380,7 @@ abstract class ActiveRecord extends BaseActiveRecord
public function delete($options = [])
{
$result = false;
if ($this->beforeDelete()) {
$result = $this->deleteInternal($options);
$this->afterDelete();
@ -384,14 +396,23 @@ abstract class ActiveRecord extends BaseActiveRecord
protected function deleteInternal($options = [])
{
$condition = $this->getOldPrimaryKey(true);
$lock = $this->optimisticLock();
if ($lock !== null) {
$condition[$lock] = $this->$lock;
}
$result = (new Query())->options($options)->collection(static::collectionName())->remove($condition);
$result = (new Query())
->options($options)
->in(static::collectionName())
->where($condition)
->remove();
if ($lock !== null && !$result) {
throw new StaleObjectException('The object being deleted is outdated.');
}
$this->setOldAttributes(null);
return $result;

View File

@ -896,6 +896,7 @@ class Query extends Component implements QueryInterface
$this->limit(1);
$statement = $this->createCommand($db);
$token = $this->getRawAql($statement);
Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
try {
Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query');
@ -942,6 +943,7 @@ class Query extends Component implements QueryInterface
$statement = $this->getStatement($params, $db);
$token = $this->getRawAql($statement);
Yii::info($token, 'mirzaev\yii2\arangodb\Query::insert');
try {
Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::insert');