diff --git a/src/Entity/InformationSchema/Column.php b/src/Entity/InformationSchema/Column.php index a291663..57ce2f8 100644 --- a/src/Entity/InformationSchema/Column.php +++ b/src/Entity/InformationSchema/Column.php @@ -72,8 +72,8 @@ class Column #[Field(name: "COLUMN_COMMENT", length: 1024)] public string $comment; - #[Field(name: "IS_GENERATED", length: 6)] - public string $generated; +# #[Field(name: "IS_GENERATED", length: 6)] +# public string $generated; #[Field(name: "GENERATION_EXPRESSION", type: "longtext")] public ? string $generationExpression; diff --git a/src/Repository.php b/src/Repository.php index 13a6ae2..8c8992d 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -13,6 +13,7 @@ use Ulmus\Annotation\Property\{Field, WithJoin, Relation\Ignore as RelationIgnore}; use Ulmus\Common\EntityResolver; +use Ulmus\Repository\WithOptionEnum; class Repository { @@ -592,7 +593,7 @@ class Repository return $this->where($primaryKeyField[$pkField]->name ?? $pkField, $value); } - public function withJoin(string|array $fields) : self + public function withJoin(string|array $fields, array $options = []) : self { if ( null === $this->queryBuilder->getFragment(Query\Select::class) ) { $select = $this->entityResolver->fieldList(EntityResolver::KEY_COLUMN_NAME, true); @@ -636,18 +637,24 @@ class Repository $this->open(); + if ( ! in_array(WithOptionEnum::SkipWhere, $options)) { foreach($this->entityResolver->searchFieldAnnotationList($item, [ Attribute\Property\Where::class, Where::class ] ) as $condition) { if ( is_object($condition->field) && ( $condition->field->entityClass !== $entity ) ) { $this->where(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->getValue(), $condition->operator); } } - - foreach($this->entityResolver->searchFieldAnnotationList($item, [ Attribute\Property\Having::class, Having::class ] ) as $condition) { - $this->having(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->getValue(), $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 ( ! in_array(WithOptionEnum::SkipHaving, $options)) { + foreach ($this->entityResolver->searchFieldAnnotationList($item, [Attribute\Property\Having::class, Having::class]) as $condition) { + $this->having(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->getValue(), $condition->operator); + } + } + + if ( ! in_array(WithOptionEnum::SkipFilter, $options)) { + 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(); @@ -656,7 +663,8 @@ class Repository $foreignKey = is_string($annotation->foreignKey) ? $entity::field($annotation->foreignKey, $alias) : $annotation->foreignKey; - $this->join("LEFT", $entity::resolveEntity()->tableName(), $key, $foreignKey, $alias, function($join) use ($item, $entity, $alias) { + $this->join("LEFT", $entity::resolveEntity()->tableName(), $key, $foreignKey, $alias, function($join) use ($item, $entity, $alias, $options) { + if ( ! in_array(WithOptionEnum::SkipJoinWhere, $options)) { foreach($this->entityResolver->searchFieldAnnotationList($item, [ Attribute\Property\Where::class, Where::class ]) as $condition) { if ( ! is_object($condition->field) ) { $field = $this->entityClass::field($condition->field); @@ -672,21 +680,24 @@ class Repository $join->where(is_object($field) ? $field : $entity::field($field, $alias), $condition->getValue(), $condition->operator); } } + } - foreach($this->entityResolver->searchFieldAnnotationList($item, [ Attribute\Property\FilterJoin::class, FilterJoin::class ]) as $filter) { - call_user_func_array([ $this->entityClass, $filter->method ], [ $join, $item, true ]); + if ( ! in_array(WithOptionEnum::SkipJoinFilter, $options) ) { + foreach ($this->entityResolver->searchFieldAnnotationList($item, [Attribute\Property\FilterJoin::class, FilterJoin::class]) as $filter) { + call_user_func_array([$this->entityClass, $filter->method], [$join, $item, true]); + } } }); } else { - throw new \Exception("Referenced field `$item` which do not exist or do not contain a valid @Join annotation."); + throw new \Exception("Referenced field `$item` which do not exist or do not contain a valid @Join or @Relation annotation."); } } return $this; } - public function withSubquery(string|array $fields) : self + public function withSubquery(string|array $fields, array $options = []) : self { # We skip subqueries when counting results since it should not affect the row count. if ( $this instanceof Repository\ServerRequestCountRepository ) { diff --git a/src/Repository/WithOptionEnum.php b/src/Repository/WithOptionEnum.php new file mode 100644 index 0000000..83a75bc --- /dev/null +++ b/src/Repository/WithOptionEnum.php @@ -0,0 +1,13 @@ +