From 1592238e5f8495dd7385848e8d65300ba7940b46 Mon Sep 17 00:00:00 2001
From: Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
Date: Tue, 16 Mar 2021 02:41:18 +1000
Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?=
 =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0?=
 =?UTF-8?q?=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4?=
 =?UTF-8?q?=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=B0:=20remove()?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 mirzaev/yii2-arangodb/ActiveRecord.php    |  2 +-
 mirzaev/yii2-arangodb/Query.php           | 17 ++++++++++-------
 mirzaev/yii2-arangodb/views/migration.php | 20 +++++++++++++++-----
 3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/mirzaev/yii2-arangodb/ActiveRecord.php b/mirzaev/yii2-arangodb/ActiveRecord.php
index 26cb641..ef05456 100644
--- a/mirzaev/yii2-arangodb/ActiveRecord.php
+++ b/mirzaev/yii2-arangodb/ActiveRecord.php
@@ -388,7 +388,7 @@ abstract class ActiveRecord extends BaseActiveRecord
         if ($lock !== null) {
             $condition[$lock] = $this->$lock;
         }
-        $result = (new Query())->options($options)->remove(static::collectionName(), $condition);
+        $result = (new Query())->options($options)->collection(static::collectionName())->remove($condition);
         if ($lock !== null && !$result) {
             throw new StaleObjectException('The object being deleted is outdated.');
         }
diff --git a/mirzaev/yii2-arangodb/Query.php b/mirzaev/yii2-arangodb/Query.php
index 49d549b..266ecc2 100644
--- a/mirzaev/yii2-arangodb/Query.php
+++ b/mirzaev/yii2-arangodb/Query.php
@@ -886,8 +886,6 @@ class Query extends Component implements QueryInterface
 
     /**
      * @param null $db
-     * @return array|bool
-     * @throws Exception
      */
     public function one($db = null)
     {
@@ -1002,14 +1000,13 @@ class Query extends Component implements QueryInterface
      * @return bool
      * @throws Exception
      */
-    public function remove($collection, $condition = [], $params = [], $db = null)
+    public function remove($condition = [], $params = [], $db = null)
     {
-        $this->collection = $collection;
         $clauses = [
-            $this->genFor($collection),
-            $this->genIn($collection),
+            static::genFor($this->for ?? $this->collection),
+            static::genIn($this->in ?? $this->collection, $this->traversals),
             $this->genWhere($condition, $params),
-            $this->genRemove($collection),
+            $this->genRemove($this->in ?? $this->collection),
             $this->genOptions(),
         ];
 
@@ -1213,6 +1210,7 @@ class Query extends Component implements QueryInterface
         $statement->setBatchSize(1);
 
         $token = $this->getRawAql($statement);
+
         Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
         try {
             Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query');
@@ -1222,6 +1220,7 @@ class Query extends Component implements QueryInterface
             Yii::endProfile($token, 'mirzaev\yii2\arangodb\Query::query');
             throw new Exception($ex->getMessage(), (int) $ex->getCode(), $ex);
         }
+
         return $cursor->getFullCount();
     }
 
@@ -1546,7 +1545,11 @@ class Query extends Component implements QueryInterface
      */
     public function limit($limit)
     {
+        // Если $limit === 0 то $limit = null
+        $limit === 0 and $limit = null;
+
         $this->limit = $limit;
+
         return $this;
     }
 
diff --git a/mirzaev/yii2-arangodb/views/migration.php b/mirzaev/yii2-arangodb/views/migration.php
index d7047e8..475a879 100644
--- a/mirzaev/yii2-arangodb/views/migration.php
+++ b/mirzaev/yii2-arangodb/views/migration.php
@@ -5,18 +5,28 @@
  */
 
 /* @var $className string the new migration class name */
-echo "<?php\n";
-?>
 
-class <?= $className ?> extends \mirzaev\yii2\arangodb\Migration
+echo <<<HTML
+<?php
+
+use mirzaev\yii2\arangodb\Migration;
+
+class $className extends Migration
 {
     public function up()
     {
-		$this->createCollection('<?= $className ?>',[]);
+        /**
+         * @param string Название коллекции
+         * @param array Тип коллекции (2 - документ, 3 - ребро)
+         */
+        \$this->createCollection('$className', ['type' => 2]);
     }
 
     public function down()
     {
-        $this->dropCollection('<?= $className ?>');
+        \$this->dropCollection('$className');
     }
 }
+HTML;
+
+?>