- Work done on search request mostly

This commit is contained in:
Dave Mc Nicoll 2026-05-21 15:19:35 +00:00
parent f938e18572
commit 7b35de3258
7 changed files with 26 additions and 14 deletions

View File

@ -103,7 +103,8 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
if ( is_a($type, Entity\Field\Date::class, true) || is_a($type, Entity\Field\Time::class, true) || is_a($type, \DateTime::class, true) ) {
$type = "TEXT";
$length = strlen((string) $type);
#$length = strlen((string) $type);
}
else {
switch($type) {

View File

@ -7,6 +7,7 @@ use Ulmus\Query;
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
class Where {
public function __construct(
public string|\Stringable|array $field,
public mixed $value = null,
@ -21,18 +22,23 @@ class Where {
public function getValue(/* null|EntityInterface */ $entity = null) : mixed
{
if ($this->generateValue) {
if ($entity) {
if ($this->generateValue) {
return call_user_func_array($this->generateValue, [ $entity ]);
}
elseif ($this->fieldValue) {
throw new \Exception(sprintf("Field value, from %s, could not be included in query since the entity is already loaded; it is meant to be used with a OneToOne relation loaded within a join.", (string) $this->fieldValue));
}
}
else {
if ($this->fieldValue) {
return $this->fieldValue;
}
elseif ($this->generateValue) {
throw new \Exception(sprintf("Could not generate value from non-instanciated entity for field %s.", (string) $this->field));
}
}
elseif ($this->fieldValue && $entity) {
throw new \Exception(sprintf("Field value, from %s, could not be included in query since the entity is already loaded; it is meant to be used with a OneToOne relation loaded within a join.", (string) $this->fieldValue));
}
return $this->fieldValue ?? $this->value;
return $this->value;
}
}

View File

@ -95,7 +95,7 @@ class EntityResolver {
return $fieldList;
}
public function relation(string $name) : array
public function relation(string $name, bool $throwOnError = true) : ? array
{
$property = $this->reflectedClass->getProperties(true)[$name] ?? false;
@ -111,8 +111,10 @@ class EntityResolver {
return [];
}
catch(\Throwable $e) {
throw new \InvalidArgumentException("Can't find entity relation's column named `$name` from entity {$this->entityClass}");
$throwOnError && throw new \InvalidArgumentException("Can't find entity relation's column named `$name` from entity {$this->entityClass}");
}
return null;
}
public function getPropertyHavingAttribute(array|object|string $type) : array

View File

@ -258,10 +258,11 @@ trait EntityTrait {
$dataset = [];
foreach($this->entityYieldDataset($objectAttribute->includeRelations ?? true, false, false) as $key => $value) {
$field = $resolver->searchField($key, EntityResolver::KEY_COLUMN_NAME);
$field = $resolver->searchField($key, EntityResolver::KEY_COLUMN_NAME); # ?: $resolver->relation($key, false);
if ($field) {
$jsonSerialize = $field->getAttribute(\Ulmus\Attribute\Property\JsonSerialize::class);
if ($jsonSerialize) {
# Should we ignore the field ?
if ($jsonSerialize->object->ignoreField) {

View File

@ -3,7 +3,7 @@
namespace Ulmus\SearchRequest\Attribute;
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
abstract class PropertyValueModifier
class PropertyValueModifier
{
public abstract function run(mixed $value) : mixed;
}

View File

@ -5,7 +5,7 @@ namespace Ulmus\SearchRequest\Attribute;
use Ulmus\SearchRequest\SearchMethodEnum;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
abstract class SearchParameter {
class SearchParameter {
public PropertyValueSource|array $source = PropertyValueSource::QueryParams;

View File

@ -38,7 +38,9 @@ trait SearchRequestFromRequestTrait
break;
case SearchMethodEnum::OrderBy:
$repository->orderBy($param->field, $param->value());
$value = $param->value();
$repository->orderBy($param->field, $value instanceof \BackedEnum ? $value->value : $value);
break;
case SearchMethodEnum::GroupBy: