改名
This commit is contained in:
@@ -219,21 +219,12 @@ class ActiveQuery extends Component
|
|||||||
public function all()
|
public function all()
|
||||||
{
|
{
|
||||||
$data = $this->modelClass::getDb()
|
$data = $this->modelClass::getDb()
|
||||||
->createCommand($this->getBuild()->count($this))
|
->createCommand($this->queryBuilder())
|
||||||
->all();
|
->all();
|
||||||
|
|
||||||
$collect = new Collection();
|
$collect = new Collection();
|
||||||
$collect->setModel($this->modelClass);
|
$collect->setModel($this->modelClass);
|
||||||
if (empty($data) || !is_array($data)) {
|
$collect->setItems($data);
|
||||||
return $this->asArray ? [] : $collect;
|
|
||||||
}
|
|
||||||
|
|
||||||
$_tmp = [];
|
|
||||||
$model = Snowflake::createObject($this->modelClass);
|
|
||||||
foreach ($data as $key => $val) {
|
|
||||||
$_tmp[] = $this->populate(clone $model, $val);
|
|
||||||
}
|
|
||||||
$collect->setItems($_tmp);
|
|
||||||
if ($this->asArray) {
|
if ($this->asArray) {
|
||||||
return $collect->toArray();
|
return $collect->toArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
|||||||
*/
|
*/
|
||||||
public function getIterator()
|
public function getIterator()
|
||||||
{
|
{
|
||||||
return new \ArrayIterator($this->_item);
|
return new CollectionIterator($this->model, $this->_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Database\Base;
|
||||||
|
|
||||||
|
|
||||||
|
use Database\ActiveRecord;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CollectionIterator
|
||||||
|
* @package Database\Base
|
||||||
|
*/
|
||||||
|
class CollectionIterator extends \ArrayIterator
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var ActiveRecord */
|
||||||
|
private $model;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct($model, $array = array(), $flags = 0)
|
||||||
|
{
|
||||||
|
$this->model = $model;
|
||||||
|
parent::__construct($array, $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ActiveRecord|mixed
|
||||||
|
*/
|
||||||
|
public function current()
|
||||||
|
{
|
||||||
|
return $this->model::populate(parent::current());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user