Commit 37664fff by Klimov Paul

Mongo Active Record created as draft.

parent dc3ada65
......@@ -7,31 +7,16 @@
namespace yii\mongo;
use yii\base\Object;
use yii\db\ActiveQueryInterface;
use yii\db\ActiveQueryTrait;
/**
* Class QueryBuilder
* Class ActiveQuery
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class QueryBuilder extends Object
class ActiveQuery extends Query implements ActiveQueryInterface
{
/**
* @var Connection the Mongo connection.
*/
public $db;
/**
* Constructor.
* @param Connection $connection the Mongo connection.
* @param array $config name-value pairs that will be used to initialize the object properties
*/
public function __construct($connection, $config = [])
{
$this->db = $connection;
parent::__construct($config);
}
// TODO
use ActiveQueryTrait;
}
\ No newline at end of file
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\mongo;
use yii\db\ActiveRelationInterface;
use yii\db\ActiveRelationTrait;
/**
* ActiveRelation represents a relation to Mongo Active Record class.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class ActiveRelation extends ActiveQuery implements ActiveRelationInterface
{
use ActiveRelationTrait;
}
\ No newline at end of file
......@@ -106,7 +106,7 @@ class Collection extends Object
* @param array $condition description of the objects to update.
* @param array $newData the object with which to update the matching records.
* @param array $options list of options in format: optionName => optionValue.
* @return boolean whether operation was successful.
* @return integer|boolean number of updated documents or whether operation was successful.
* @throws Exception on failure.
*/
public function update($condition, $newData, $options = [])
......@@ -115,9 +115,14 @@ class Collection extends Object
Yii::info($token, __METHOD__);
try {
Yii::beginProfile($token, __METHOD__);
$this->mongoCollection->update($this->buildCondition($condition), $newData, $options);
$result = $this->mongoCollection->update($this->buildCondition($condition), $newData, $options);
$this->tryResultError($result);
Yii::endProfile($token, __METHOD__);
return true;
if (is_array($result) && array_key_exists('n', $result)) {
return $result['n'];
} else {
return true;
}
} catch (\Exception $e) {
Yii::endProfile($token, __METHOD__);
throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
......@@ -150,7 +155,7 @@ class Collection extends Object
* Removes data from the collection.
* @param array $condition description of records to remove.
* @param array $options list of options in format: optionName => optionValue.
* @return boolean whether operation was successful.
* @return integer|boolean number of updated documents or whether operation was successful.
* @throws Exception on failure.
*/
public function remove($condition = [], $options = [])
......@@ -159,9 +164,14 @@ class Collection extends Object
Yii::info($token, __METHOD__);
try {
Yii::beginProfile($token, __METHOD__);
$this->tryResultError($this->mongoCollection->remove($this->buildCondition($condition), $options));
$result = $this->mongoCollection->remove($this->buildCondition($condition), $options);
$this->tryResultError($result);
Yii::endProfile($token, __METHOD__);
return true;
if (is_array($result) && array_key_exists('n', $result)) {
return $result['n'];
} else {
return true;
}
} catch (\Exception $e) {
Yii::endProfile($token, __METHOD__);
throw new Exception($e->getMessage(), (int)$e->getCode(), $e);
......
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