This commit is contained in:
Dave Mc Nicoll committed 2020-11-27 12:21:10 -05:00
commit f74d1907d9
21 files changed
+759 -555

No files matched your search

+22 -11
View File
@@ -35,12 +35,11 @@ trait EntityTrait {
public function __get(string $name)
{
$entityResolver = $this->resolveEntity();
# Resolve relations here if one is called
# @TODO REFACTOR THIS CODE ASAP !
if ( $this->isLoaded() ) {
if ( null !== ( $join= $entityResolver->searchFieldAnnotation($name, new Join() ) ) ) {
$vars = [];
@@ -60,7 +59,7 @@ trait EntityTrait {
}
if ( null !== ( $relation = $entityResolver->searchFieldAnnotation($name, new Relation() ) ) ) {
$relationType = strtolower(str_replace(['-', '_'], '', $relation->type));
$relationType = strtolower(str_replace(['-', '_', ' '], '', $relation->type));
$order = $entityResolver->searchFieldAnnotationList($name, new OrderBy() );
$where = $entityResolver->searchFieldAnnotationList($name, new Where() );
@@ -117,7 +116,7 @@ trait EntityTrait {
if ($relationRelation === null) {
throw new \Exception("@Relation annotation not found for field `{$relation->foreignField}` in entity {$relation->bridge}");
}
$repository = $relationRelation->entity()->repository();
$bridgeAlias = uniqid("bridge_");
@@ -168,10 +167,7 @@ trait EntityTrait {
return;
}
}
else {
}
throw new \Exception(sprintf("[%s] - Undefined variable: %s", static::class, $name));
}
@@ -183,7 +179,7 @@ trait EntityTrait {
if ( $this->isLoaded() && static::resolveEntity()->searchFieldAnnotation($name, new Relation() ) ) {
return true;
}
return isset($this->$name);
}
@@ -250,6 +246,21 @@ trait EntityTrait {
return $this;
}
public function resetVirtualProperties() : self
{
foreach($this->resolveEntity()->properties as $prop => $property) {
if ( ! $property['builtin'] ) {
foreach($property['tags'] as $tag) {
if ( in_array(strtolower($tag['tag']), [ 'relation', 'join' ] ) ) {
unset($this->$prop);
}
}
}
}
return $this;
}
/**
* @Ignore
@@ -391,7 +402,7 @@ trait EntityTrait {
{
$collection = new EntityCollection(...$arguments);
$collection->entityClass = static::class;
return $collection;
}