- Select now only query existing entity's fields on select() and withJoin() statements.
This commit is contained in:
parent
70021d829d
commit
88e9f048db
|
@ -40,8 +40,8 @@ trait EntityTrait {
|
|||
$entityResolver = $this->resolveEntity();
|
||||
|
||||
foreach($dataset as $key => $value) {
|
||||
$field = $entityResolver->field(strtolower($key), EntityResolver::KEY_COLUMN_NAME, false) ?? null;
|
||||
|
||||
$field = $entityResolver->field(strtolower($key), EntityResolver::KEY_COLUMN_NAME, false) ?? null;
|
||||
$field ??= $entityResolver->field(strtolower($key), EntityResolver::KEY_LC_ENTITY_NAME, false);
|
||||
|
||||
if ( $field === null ) {
|
||||
|
@ -232,7 +232,12 @@ trait EntityTrait {
|
|||
|
||||
public function __sleep()
|
||||
{
|
||||
return array_keys($this->resolveEntity()->fieldList());
|
||||
return array_merge(array_keys($this->resolveEntity()->fieldList()), [ 'entityLoadedDataset' ] );
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->resetVirtualProperties();
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
|
@ -248,7 +253,7 @@ trait EntityTrait {
|
|||
}
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->entityGetDataset();
|
||||
}
|
||||
|
|
|
@ -586,7 +586,8 @@ class Repository
|
|||
public function withJoin(string|array $fields) : self
|
||||
{
|
||||
if ( null === $this->queryBuilder->getFragment(Query\Select::class) ) {
|
||||
$this->select("{$this->alias}.*");
|
||||
$select = $this->entityResolver->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
|
||||
$this->select($this->entityClass::fields(array_map(fn($f) => $f['object']->name ?? $f['name'], $select)));
|
||||
}
|
||||
|
||||
# @TODO Apply FILTER annotation to this too !
|
||||
|
@ -898,7 +899,8 @@ class Repository
|
|||
protected function selectSqlQuery() : self
|
||||
{
|
||||
if ( null === $this->queryBuilder->getFragment(Query\Select::class) ) {
|
||||
$this->select("{$this->alias}.*");
|
||||
$fields = $this->entityResolver->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
|
||||
$this->select($this->entityClass::fields(array_map(fn($f) => $f['object']->name ?? $f['name'], $fields)));
|
||||
}
|
||||
|
||||
if ( null === $this->queryBuilder->getFragment(Query\From::class) ) {
|
||||
|
|
Loading…
Reference in New Issue