改名
This commit is contained in:
@@ -114,7 +114,13 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
||||
*/
|
||||
public function getModel(): ActiveRecord
|
||||
{
|
||||
return objectPool($this->model);
|
||||
$model = $this->model;;
|
||||
if (is_object($model)) {
|
||||
return $model;
|
||||
}
|
||||
return objectPool($model, function () use ($model) {
|
||||
return new $model();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -907,8 +907,12 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
||||
*/
|
||||
public static function populate(array $data): static
|
||||
{
|
||||
$className = get_called_class();
|
||||
|
||||
/** @var static $model */
|
||||
$model = objectPool(get_called_class());
|
||||
$model = objectPool($className, function () use ($className) {
|
||||
return new $className();
|
||||
});
|
||||
$model->attributes = $data;
|
||||
$model->setIsCreate(false);
|
||||
return $model;
|
||||
|
||||
@@ -56,7 +56,13 @@ class CollectionIterator extends \ArrayIterator
|
||||
*/
|
||||
protected function newModel($current): ActiveRecord
|
||||
{
|
||||
return objectPool($this->model)->setAttributes($current);
|
||||
$model = $this->model;
|
||||
if (is_object($model)) {
|
||||
return $model->setAttributes($current);
|
||||
}
|
||||
return objectPool($model, function () use ($model) {
|
||||
return new $model();
|
||||
})->setAttributes($current);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user