diff --git a/src/Adapter/SQLite.php b/src/Adapter/SQLite.php index 0f585d5..281dff3 100644 --- a/src/Adapter/SQLite.php +++ b/src/Adapter/SQLite.php @@ -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) { diff --git a/src/Attribute/Property/Where.php b/src/Attribute/Property/Where.php index 3dc9f9b..8312ed6 100644 --- a/src/Attribute/Property/Where.php +++ b/src/Attribute/Property/Where.php @@ -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 ($entity) { + if ($this->generateValue) { return call_user_func_array($this->generateValue, [ $entity ]); } - else { + 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; } } diff --git a/src/Common/EntityResolver.php b/src/Common/EntityResolver.php index a8e9306..ba16930 100644 --- a/src/Common/EntityResolver.php +++ b/src/Common/EntityResolver.php @@ -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 diff --git a/src/EntityTrait.php b/src/EntityTrait.php index 23c62b3..f3195bd 100644 --- a/src/EntityTrait.php +++ b/src/EntityTrait.php @@ -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) { diff --git a/src/SearchRequest/Attribute/PropertyValueModifier.php b/src/SearchRequest/Attribute/PropertyValueModifier.php index 69755c0..9ea4ae7 100644 --- a/src/SearchRequest/Attribute/PropertyValueModifier.php +++ b/src/SearchRequest/Attribute/PropertyValueModifier.php @@ -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; } \ No newline at end of file diff --git a/src/SearchRequest/Attribute/SearchParameter.php b/src/SearchRequest/Attribute/SearchParameter.php index 5c2eafe..24874c3 100644 --- a/src/SearchRequest/Attribute/SearchParameter.php +++ b/src/SearchRequest/Attribute/SearchParameter.php @@ -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; diff --git a/src/SearchRequest/SearchRequestFromRequestTrait.php b/src/SearchRequest/SearchRequestFromRequestTrait.php index 3f52a8e..5af57cc 100644 --- a/src/SearchRequest/SearchRequestFromRequestTrait.php +++ b/src/SearchRequest/SearchRequestFromRequestTrait.php @@ -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: