改名
This commit is contained in:
@@ -126,7 +126,12 @@ class ActiveRecord extends BaseActiveRecord
|
||||
if (empty($attributes)) {
|
||||
return \logger()->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
|
||||
}
|
||||
$select = objectPool(self::class);
|
||||
|
||||
$className = get_called_class();
|
||||
$select = objectPool($className, function () use ($className) {
|
||||
return new $className();
|
||||
});
|
||||
|
||||
$select->attributes = $attributes;
|
||||
if (!$select->save()) {
|
||||
throw new Exception($select->getLastError());
|
||||
@@ -342,7 +347,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
|
||||
$relation = $this->getRelation();
|
||||
|
||||
return objectPool(HasOne::class, [$modelName, $foreignKey, $value, $relation]);
|
||||
return new HasOne($modelName, $foreignKey, $value, $relation);
|
||||
}
|
||||
|
||||
|
||||
@@ -363,7 +368,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
|
||||
$relation = $this->getRelation();
|
||||
|
||||
return objectPool(HasCount::class, [$modelName, $foreignKey, $value, $relation]);
|
||||
return new HasCount($modelName, $foreignKey, $value, $relation);
|
||||
}
|
||||
|
||||
|
||||
@@ -384,7 +389,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
|
||||
$relation = $this->getRelation();
|
||||
|
||||
return objectPool(HasMany::class, [$modelName, $foreignKey, $value, $relation]);
|
||||
return new HasMany($modelName, $foreignKey, $value, $relation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -404,7 +409,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
|
||||
$relation = $this->getRelation();
|
||||
|
||||
return objectPool(HasMany::class, [$modelName, $foreignKey, $value, $relation]);
|
||||
return new HasMany($modelName, $foreignKey, $value, $relation);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ class Collection extends AbstractCollection
|
||||
}
|
||||
$_filters[] = $value;
|
||||
}
|
||||
return objectPool(Collection::class, [$this->query, $_filters, $this->model]);
|
||||
return new Collection($this->query, $_filters, $this->model);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user