diff --git a/src/Attribute/Property/Relation.php b/src/Attribute/Property/Relation.php index 7497493..9a8ddb6 100644 --- a/src/Attribute/Property/Relation.php +++ b/src/Attribute/Property/Relation.php @@ -7,7 +7,7 @@ use Ulmus\Attribute\Attribute; #[\Attribute(\Attribute::TARGET_PROPERTY)] class Relation { public function __construct( - public string $type, + public Relation\RelationTypeEnum|string $type, public \Stringable|string|array $key = "", public null|\Closure $generateKey = null, public null|\Stringable|string|array $foreignKey = null, @@ -29,7 +29,6 @@ class Relation { $this->bridgeField = Attribute::handleArrayField($this->bridgeField); $this->bridgeForeignKey = Attribute::handleArrayField($this->bridgeForeignKey); $this->field = Attribute::handleArrayField($this->field); - } public function entity() { @@ -55,17 +54,17 @@ class Relation { public function isOneToOne() : bool { - return $this->normalizeType() === 'onetoone'; + return $this->type === Relation\RelationTypeEnum::oneToOne || $this->normalizeType() === 'onetoone'; } public function isOneToMany() : bool { - return $this->normalizeType() === 'onetomany'; + return $this->type === Relation\RelationTypeEnum::oneToMany || $this->normalizeType() === 'onetomany'; } public function isManyToMany() : bool { - return $this->normalizeType() === 'manytomany'; + return $this->type === Relation\RelationTypeEnum::manyToMany || $this->normalizeType() === 'manytomany'; } public function function() : string diff --git a/src/Attribute/Property/Relation/RelationTypeEnum.php b/src/Attribute/Property/Relation/RelationTypeEnum.php new file mode 100644 index 0000000..43f35f7 --- /dev/null +++ b/src/Attribute/Property/Relation/RelationTypeEnum.php @@ -0,0 +1,10 @@ +field = Attribute::handleArrayField($field); + + if ($foreignField) { + $this->value = Attribute::handleArrayField($foreignField); + } } } diff --git a/src/Repository.php b/src/Repository.php index 3bb7345..d1a3070 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -628,8 +628,10 @@ class Repository $this->having(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->value, $condition->operator); } - foreach($this->entityResolver->searchFieldAnnotationList($item, [ Attribute\Property\Filter::class, Filter::class ] ) as $filter) { - call_user_func_array([ $this->entityClass, $filter->method ], [ $this, $item, true ]); + if ( empty($this->entityResolver->searchFieldAnnotationList($item, [ Attribute\Property\FilterJoin::class, FilterJoin::class ])) ) { + foreach ($this->entityResolver->searchFieldAnnotationList($item, [Attribute\Property\Filter::class, Filter::class]) as $filter) { + call_user_func_array([$this->entityClass, $filter->method], [$this, $item, true]); + } } $this->close(); @@ -700,7 +702,7 @@ class Repository $repository = $entity::repository()->selectJsonEntity($entity, $alias)->open(); } - # $relation->isManyToMany() and $repository->selectJsonEntity($relation->bridge, $relation->bridgeField, true); + # @TODO ? $relation->isManyToMany() and $repository->selectJsonEntity($relation->bridge, $relation->bridgeField, true); foreach($this->entityResolver->searchFieldAnnotationList($item, [ Attribute\Property\Where::class, Where::class ]) as $condition) { $repository->where(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->value, $condition->operator);