This commit is contained in:
2021-11-11 03:11:41 +08:00
parent 229c0fa523
commit 07a40f4449
3 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -134,7 +134,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
return NULL; return NULL;
} }
if (!($this->_item[$offset] instanceof ModelInterface)) { if (!($this->_item[$offset] instanceof ModelInterface)) {
return $this->model::populate($this->_item[$offset]); return $this->model->setAttributes($this->_item[$offset]);
} }
return $this->_item[$offset]; return $this->_item[$offset];
} }
+2 -2
View File
@@ -17,7 +17,7 @@ use Exception;
class CollectionIterator extends \ArrayIterator class CollectionIterator extends \ArrayIterator
{ {
private \Database\Model|string $model; private ModelInterface|string $model;
/** @var ActiveQuery */ /** @var ActiveQuery */
@@ -56,7 +56,7 @@ class CollectionIterator extends \ArrayIterator
*/ */
protected function newModel($current): ModelInterface protected function newModel($current): ModelInterface
{ {
return $this->model::populate($current); return $this->model->setAttributes($current);
} }
+3 -2
View File
@@ -33,9 +33,10 @@ interface ModelInterface
/** /**
* @return string * @param array $data
* @return static
*/ */
public static function className(): string; public static function populate(array $data): static;
/** /**