- Added a 'select' attribute, WIP on ArrayCollection and ArrayOf also
This commit is contained in:
1 parent
b394b9348f
commit
f938e18572
7 files changed
+56
-34
No files matched your search
+13
-8
@@ -59,7 +59,7 @@ class Repository implements RepositoryInterface
|
||||
|
||||
public function loadOne() : ? object
|
||||
{
|
||||
return $this->limit(1)->selectSqlQuery()->collectionFromQuery()[0] ?? null;
|
||||
return $this->limit(1)->loadAll()[0] ?? null;
|
||||
}
|
||||
|
||||
public function loadOneFromField($field, $value) : ? object
|
||||
@@ -72,11 +72,12 @@ class Repository implements RepositoryInterface
|
||||
return $primaryKey ? $this->loadOneFromField($primaryKey, $value) : $this->wherePrimaryKey($value)->loadOne();
|
||||
}
|
||||
|
||||
public function loadAll () : EntityCollection
|
||||
public function loadAll() : EntityCollection
|
||||
{
|
||||
return $this->selectSqlQuery()->collectionFromQuery();
|
||||
}
|
||||
|
||||
#[\Deprecated(message: "loadFromField is now to be used instead of this method")]
|
||||
public function loadAllFromField($field, $value, $operator= Query\Where::OPERATOR_EQUAL) : EntityCollection
|
||||
{
|
||||
return $this->loadFromField($field, $value, $operator);
|
||||
@@ -84,7 +85,7 @@ class Repository implements RepositoryInterface
|
||||
|
||||
public function loadFromField($field, $value, $operator= Query\Where::OPERATOR_EQUAL) : EntityCollection
|
||||
{
|
||||
return $this->selectSqlQuery()->where($field, $value, $operator)->collectionFromQuery();
|
||||
return $this->where($field, $value, $operator)->loadAll();
|
||||
}
|
||||
|
||||
public function count() : int
|
||||
@@ -245,8 +246,6 @@ class Repository implements RepositoryInterface
|
||||
|
||||
$diff = $fieldsAndValue ?? $this->generateWritableDataset($entity);
|
||||
|
||||
# dump($diff);
|
||||
|
||||
if ( [] !== $diff ) {
|
||||
if ($primaryKeyDefinition) {
|
||||
$pkField = key($primaryKeyDefinition);
|
||||
@@ -263,7 +262,6 @@ class Repository implements RepositoryInterface
|
||||
|
||||
$entity->entityFillFromDataset($dataset, true);
|
||||
|
||||
# $fieldsAndValue ??= &$dataset;
|
||||
$this->eventExecute(Event\Query\Update::class, $this, $entity, $dataset, $replace);
|
||||
|
||||
return $update ? (bool) $update->rowCount : false;
|
||||
@@ -400,6 +398,7 @@ class Repository implements RepositoryInterface
|
||||
|
||||
foreach ($entity::resolveEntity()->fieldList(Common\EntityResolver::KEY_COLUMN_NAME, true) as $key => $field) {
|
||||
if (null === $entity::resolveEntity()->searchFieldAnnotation($field->name, [ Relation\Ignore::class ])) {
|
||||
# @TODO add handling of the new #[Select] attribute here !
|
||||
$this->select(sprintf("%s.$key as {$prependField}{$field->name}", $this->escapeIdentifier($alias)));
|
||||
}
|
||||
}
|
||||
@@ -456,7 +455,7 @@ class Repository implements RepositoryInterface
|
||||
|
||||
if ( $canSelect ) {
|
||||
$select = $this->entityResolver->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
|
||||
$this->select($this->entityClass::fields(array_map(fn($f) => $f['object']->name ?? $f['name'], $select)));
|
||||
$this->select($this->entityClass::fields(array_map(fn($f) => $f['object']->name ?? $f['name'], $select), select: true));
|
||||
}
|
||||
|
||||
$fields = (array) $fields;
|
||||
@@ -488,6 +487,8 @@ class Repository implements RepositoryInterface
|
||||
$name = $entity::resolveEntity()->searchFieldAnnotation($field->name, [ Field::class ])->name ?? $field->name;
|
||||
|
||||
if ($canSelect) {
|
||||
# @TODO add handling of the new #[Select] attribute here !
|
||||
|
||||
$this->select("$escAlias.$fieldName as $alias\${$name}");
|
||||
}
|
||||
}
|
||||
@@ -563,7 +564,11 @@ class Repository implements RepositoryInterface
|
||||
}
|
||||
|
||||
if ( null === $this->queryBuilder->getFragment(Query\Select::class) ) {
|
||||
$this->select($this->escapeIdentifier($this->alias) . ".*");
|
||||
# @TODO add handling of the new #[Select] attribute here !
|
||||
$select = $this->entityResolver->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
|
||||
$this->select($this->entityClass::fields(array_map(fn($f) => $f['object']->name ?? $f['name'], $select), alias: $this->alias, select: true));
|
||||
|
||||
# $this->select($this->escapeIdentifier($this->alias) . ".*");
|
||||
}
|
||||
|
||||
# Apply FILTER annotation to this too !
|
||||
|
||||
Reference in new issue
Block a user