This commit is contained in:
2021-02-23 17:43:13 +08:00
parent 29fc384741
commit 1c0cd04fcc
6 changed files with 37 additions and 14 deletions
+2 -2
View File
@@ -181,7 +181,7 @@ class ActiveQuery extends Component
*/
public function page(int $size, callable $callback): Pagination
{
$pagination = objectPool(Pagination::class, [$this]);
$pagination = new Pagination($this);
$pagination->setOffset(0);
$pagination->setLimit($size);
$pagination->setCallback($callback);
@@ -207,7 +207,7 @@ class ActiveQuery extends Component
public function all(): Collection|array
{
$data = $this->modelClass::getDb()->createCommand($this->queryBuilder())->all();
$collect = objectPool(Collection::class, [$this, $data, $this->modelClass]);
$collect = new Collection($this, $data, $this->modelClass);
if ($this->asArray) {
return $collect->toArray();
}
+12 -6
View File
@@ -315,11 +315,6 @@ class ActiveRecord extends BaseActiveRecord
*/
public function toArray(): array
{
$class = $this;
Coroutine::defer(function () use ($class) {
$object = Snowflake::app()->getObject();
$object->release(get_called_class(), $class);
});
$data = $this->_attributes;
foreach ($this->getAnnotation() as $key => $item) {
if (!isset($data[$key])) {
@@ -327,7 +322,18 @@ class ActiveRecord extends BaseActiveRecord
}
$data[$key] = call_user_func([$this, $item[1]], $data[$key]);
}
return array_merge($data, $this->runRelate());
$data = array_merge($data, $this->runRelate());
$this->recover();
return $data;
}
/**
* @throws ComponentException
*/
public function recover()
{
objectRecover(get_called_class(), $this);
}