- Added a LoadRelation for the repository.
- Added a new @Filter() annotation to the relation; adding it to JOIN is also coming. - Some bugfixes done within the Where and ConditionTrait.
This commit is contained in:
1 parent
9e84bd3536
commit
7dd64abf29
6 files changed
+136
-24
No files matched your search
+15
-5
@@ -8,7 +8,7 @@ use Ulmus\Repository,
|
||||
Ulmus\Common\EntityField;
|
||||
|
||||
use Ulmus\Annotation\Classes\{ Method, Table, Collation, };
|
||||
use Ulmus\Annotation\Property\{ Field, Relation, OrderBy, Where, Join, Virtual };
|
||||
use Ulmus\Annotation\Property\{ Field, Filter, Relation, OrderBy, Where, Join, Virtual };
|
||||
use Ulmus\Annotation\Property\Field\{ Id, ForeignKey, CreatedAt, UpdatedAt, };
|
||||
|
||||
trait EntityTrait {
|
||||
@@ -63,14 +63,15 @@ trait EntityTrait {
|
||||
|
||||
$order = $entityResolver->searchFieldAnnotationList($name, new OrderBy() );
|
||||
$where = $entityResolver->searchFieldAnnotationList($name, new Where() );
|
||||
|
||||
$filters = $entityResolver->searchFieldAnnotationList($name, new Filter() );
|
||||
|
||||
if ( $relation->entity ?? false ) {
|
||||
$baseEntity = $relation->entity();
|
||||
|
||||
$repository = $baseEntity->repository();
|
||||
|
||||
foreach($where as $condition) {
|
||||
$repository->where($condition->field, is_callable($condition->value) ? $f = call_user_func_array($condition->value, [ $this ]) : $condition->value, $condition->operator);
|
||||
$repository->where($condition->field, is_callable($condition->value) ? call_user_func_array($condition->value, [ $this ]) : $condition->value, $condition->operator, $condition->condition);
|
||||
}
|
||||
|
||||
foreach($order as $item) {
|
||||
@@ -79,6 +80,14 @@ trait EntityTrait {
|
||||
|
||||
$field = $relation->key;
|
||||
}
|
||||
|
||||
$applyFilter = function($repository) use ($filters, $name) {
|
||||
foreach($filters as $filter) {
|
||||
$repository = call_user_func_array([ $this, $filter->method ], [ $repository, $name ]);
|
||||
}
|
||||
|
||||
return $repository;
|
||||
};
|
||||
|
||||
switch( $relationType ) {
|
||||
case 'onetoone':
|
||||
@@ -100,9 +109,10 @@ trait EntityTrait {
|
||||
if ($relation->foreignKey) {
|
||||
$repository->where( is_object($relation->foreignKey) ? $relation->foreignKey : $baseEntity->field($relation->foreignKey), is_callable($field) ? $field($this) : $this->$field );
|
||||
}
|
||||
|
||||
$this->eventExecute(Event\EntityRelationLoadInterface::class, $name, $repository);
|
||||
|
||||
return $this->$name = call_user_func([$repository, $relation->function]);
|
||||
return $this->$name = call_user_func([$applyFilter($repository), $relation->function]);
|
||||
|
||||
case 'manytomany':
|
||||
if ( false === $relation->bridge ?? false ) {
|
||||
@@ -138,7 +148,7 @@ trait EntityTrait {
|
||||
|
||||
$this->eventExecute(Event\EntityRelationLoadInterface::class, $name, $repository);
|
||||
|
||||
$this->$name = call_user_func([ $repository, $relationRelation->function ]);
|
||||
$this->$name = call_user_func([ $applyFilter($repository), $relationRelation->function ]);
|
||||
|
||||
if ($relation->bridgeField ?? false) {
|
||||
$repository = $relationRelation->entity::repository();
|
||||
|
||||
Reference in new issue
Block a user