- WIP on locale formatting since strftime is deprecated
- Added Limit and Offset attributes in RelationBuilder
This commit is contained in:
1 parent
2f482324b2
commit
b33c67b594
4 files changed
+50
-4
No files matched your search
@@ -6,9 +6,7 @@ use Ulmus\{
|
||||
Ulmus, Query, Common\EntityResolver, Repository, Event, Common\Sql
|
||||
};
|
||||
|
||||
use Ulmus\Attribute\Property\{
|
||||
Filter, Join, OrderBy, Relation, Virtual, Where, WithJoin,
|
||||
};
|
||||
use Ulmus\Attribute\Property\{Filter, Join, Limit, Offset, OrderBy, Relation, Virtual, Where, WithJoin};
|
||||
|
||||
class RelationBuilder
|
||||
{
|
||||
@@ -30,6 +28,10 @@ class RelationBuilder
|
||||
|
||||
protected array $joins;
|
||||
|
||||
protected ? Limit $limit;
|
||||
|
||||
protected ? Offset $offset;
|
||||
|
||||
public function __construct(string|object $entity, ? Repository $repository = null)
|
||||
{
|
||||
$this->entity = $entity;
|
||||
@@ -93,6 +95,8 @@ class RelationBuilder
|
||||
{
|
||||
if ( null !== ( $relation = $this->resolver->searchFieldAnnotation($name, [ Relation::class ] ) ) ) {
|
||||
$this->orders = $this->resolver->searchFieldAnnotationList($name, [ OrderBy::class ] );
|
||||
$this->limit = $this->resolver->searchFieldAnnotation($name, [ Limit::class ] );
|
||||
$this->offset = $this->resolver->searchFieldAnnotation($name, [ Offset::class ] );
|
||||
$this->wheres = $this->resolver->searchFieldAnnotationList($name, [ Where::class ] );
|
||||
$this->filters = $this->resolver->searchFieldAnnotationList($name, [ Filter::class ] );
|
||||
$this->joins = $this->resolver->searchFieldAnnotationList($name, [ WithJoin::class ] );
|
||||
@@ -184,6 +188,17 @@ class RelationBuilder
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyLimits() : void
|
||||
{
|
||||
if ($this->limit) {
|
||||
$this->repository->limit($this->limit->value);
|
||||
}
|
||||
|
||||
if ($this->offset) {
|
||||
$this->repository->offset($this->offset->value);
|
||||
}
|
||||
}
|
||||
|
||||
protected function instanciateEmptyEntity(string $name, Relation $relation) : object
|
||||
{
|
||||
$class = $relation->entity ?? $this->resolver->reflectedClass->getProperties()[$name]->getTypes()[0]->type;
|
||||
@@ -264,7 +279,7 @@ class RelationBuilder
|
||||
|
||||
public function oneToOne(string $name, Relation $relation) : Repository
|
||||
{
|
||||
return $this->oneToMany($name, $relation)->limit(1);
|
||||
return $this->oneToMany($name, $relation)->limit($this->limit->value ?? 1);
|
||||
}
|
||||
|
||||
public function oneToMany(string $name, Relation $relation) : Repository
|
||||
@@ -279,6 +294,8 @@ class RelationBuilder
|
||||
|
||||
$this->applyWithJoin();
|
||||
|
||||
$this->applyLimits();
|
||||
|
||||
$field = $relation->key;
|
||||
|
||||
if ($relation->foreignKey) {
|
||||
@@ -324,6 +341,8 @@ class RelationBuilder
|
||||
|
||||
$this->applyWithJoin();
|
||||
|
||||
$this->applyLimits();
|
||||
|
||||
if ($selectBridgeField && $relation->bridgeField) {
|
||||
$this->repository->selectEntity($relation->bridge, $bridgeAlias, $bridgeAlias);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user