- Fixed RelationBuilder problem whenever a field wasn't set
This commit is contained in:
		
							parent
							
								
									cc6048d4ee
								
							
						
					
					
						commit
						8fff21ecb0
					
				| @ -3,7 +3,7 @@ | ||||
| namespace Ulmus\Repository; | ||||
| 
 | ||||
| use Ulmus\{ | ||||
|     Ulmus, Query, Common\EntityResolver, Repository, Event, | ||||
|     Ulmus, Query, Common\EntityResolver, Repository, Event, Common\Sql | ||||
| }; | ||||
| 
 | ||||
| use Ulmus\Attribute\Property\{ | ||||
| @ -91,7 +91,7 @@ class RelationBuilder | ||||
| 
 | ||||
|     protected function resolveRelation(string $name) : mixed | ||||
|     { | ||||
|         if ( null !== ( $relation = $this->resolver->searchFieldAnnotation($name, [ Relation::class, /*Join::class*/ ] ) ) ) { | ||||
|         if ( null !== ( $relation = $this->resolver->searchFieldAnnotation($name, [ Relation::class ] ) ) ) { | ||||
|             $this->orders = $this->resolver->searchFieldAnnotationList($name, [ OrderBy::class ] ); | ||||
|             $this->wheres = $this->resolver->searchFieldAnnotationList($name, [  Where::class ] ); | ||||
|             $this->filters = $this->resolver->searchFieldAnnotationList($name, [ Filter::class ] ); | ||||
| @ -276,11 +276,16 @@ class RelationBuilder | ||||
|             if ( $relation->generateKey ) { | ||||
|                 $value = call_user_func_array($relation->generateKey, [ $this->entity ]); | ||||
|             } | ||||
|             else { | ||||
|             elseif (isset($this->entity->$field)) { | ||||
|                 $value = $this->entity->$field; | ||||
|             } | ||||
| 
 | ||||
|             $this->repository->where( is_object($relation->foreignKey) ? $relation->foreignKey : $baseEntity::field($relation->foreignKey), $value ); | ||||
|             if (isset($value)) { | ||||
|                 $this->repository->where( is_object($relation->foreignKey) ? $relation->foreignKey : $baseEntity::field($relation->foreignKey), $value ); | ||||
|             } | ||||
|             else { | ||||
|                 $this->repository->where(Sql::raw('TRUE'), Sql::raw('FALSE')); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return $this->applyFilter($this->repository, $name); | ||||
| @ -340,7 +345,7 @@ class RelationBuilder | ||||
| 
 | ||||
|         return []; | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     protected function fieldIsNullable(string $name) : bool | ||||
|     { | ||||
|         return $this->resolver->reflectedClass->getProperties(true)[$name]->allowsNull(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user