NoFetch Attribute
This commit is contained in:
parent
e37b9355b9
commit
e4e2511d1c
7
Core/Objects/DatabaseEntity/Attribute/NoFetch.class.php
Normal file
7
Core/Objects/DatabaseEntity/Attribute/NoFetch.class.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Core\Objects\DatabaseEntity\Attribute;
|
||||||
|
|
||||||
|
#[\Attribute(\Attribute::TARGET_PROPERTY)] class NoFetch {
|
||||||
|
|
||||||
|
}
|
@ -35,6 +35,7 @@ use Core\Objects\DatabaseEntity\Attribute\Json;
|
|||||||
use Core\Objects\DatabaseEntity\Attribute\MaxLength;
|
use Core\Objects\DatabaseEntity\Attribute\MaxLength;
|
||||||
use Core\Objects\DatabaseEntity\Attribute\Multiple;
|
use Core\Objects\DatabaseEntity\Attribute\Multiple;
|
||||||
use Core\Objects\DatabaseEntity\Attribute\MultipleReference;
|
use Core\Objects\DatabaseEntity\Attribute\MultipleReference;
|
||||||
|
use Core\Objects\DatabaseEntity\Attribute\NoFetch;
|
||||||
use Core\Objects\DatabaseEntity\Attribute\Transient;
|
use Core\Objects\DatabaseEntity\Attribute\Transient;
|
||||||
use Core\Objects\DatabaseEntity\Attribute\Unique;
|
use Core\Objects\DatabaseEntity\Attribute\Unique;
|
||||||
|
|
||||||
@ -349,12 +350,13 @@ class DatabaseEntityHandler implements Persistable {
|
|||||||
} else if ($column instanceof JsonColumn) {
|
} else if ($column instanceof JsonColumn) {
|
||||||
$value = json_decode($value, true);
|
$value = json_decode($value, true);
|
||||||
} else if (isset($this->relations[$propertyName])) {
|
} else if (isset($this->relations[$propertyName])) {
|
||||||
|
$property = $this->properties[$propertyName];
|
||||||
$relationHandler = $this->relations[$propertyName];
|
$relationHandler = $this->relations[$propertyName];
|
||||||
$relColumnPrefix = self::buildColumnName($propertyName) . "_";
|
$relColumnPrefix = self::buildColumnName($propertyName) . "_";
|
||||||
if (array_key_exists($relColumnPrefix . "id", $row)) {
|
if (array_key_exists($relColumnPrefix . "id", $row)) {
|
||||||
$relId = $row[$relColumnPrefix . "id"];
|
$relId = $row[$relColumnPrefix . "id"];
|
||||||
if ($relId !== null) {
|
if ($relId !== null) {
|
||||||
if ($fetchEntities !== DatabaseEntityQuery::FETCH_NONE) {
|
if ($fetchEntities !== DatabaseEntityQuery::FETCH_NONE && !self::getAttribute($property, NoFetch::class)) {
|
||||||
if ($this === $relationHandler) {
|
if ($this === $relationHandler) {
|
||||||
|
|
||||||
if ($context) {
|
if ($context) {
|
||||||
@ -591,6 +593,9 @@ class DatabaseEntityHandler implements Persistable {
|
|||||||
$nmTable = $nmRelation->getTableName();
|
$nmTable = $nmRelation->getTableName();
|
||||||
$property = $this->properties[$nmProperty];
|
$property = $this->properties[$nmProperty];
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
if (self::getAttribute($property, NoFetch::class)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($nmRelation instanceof NMRelation) {
|
if ($nmRelation instanceof NMRelation) {
|
||||||
$thisIdColumn = $nmRelation->getIdColumn($this);
|
$thisIdColumn = $nmRelation->getIdColumn($this);
|
||||||
|
@ -7,6 +7,7 @@ use Core\Driver\SQL\Column\Column;
|
|||||||
use Core\Driver\SQL\Expression\Alias;
|
use Core\Driver\SQL\Expression\Alias;
|
||||||
use Core\Driver\SQL\Query\Select;
|
use Core\Driver\SQL\Query\Select;
|
||||||
use Core\Driver\SQL\SQL;
|
use Core\Driver\SQL\SQL;
|
||||||
|
use Core\Objects\DatabaseEntity\Attribute\NoFetch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this class is similar to \Driver\SQL\Query\Select but with reduced functionality
|
* this class is similar to \Driver\SQL\Query\Select but with reduced functionality
|
||||||
@ -92,7 +93,6 @@ class DatabaseEntityQuery extends Select {
|
|||||||
return new DatabaseEntityQuery($handler, SQL::FETCH_ONE);
|
return new DatabaseEntityQuery($handler, SQL::FETCH_ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: clean this up
|
|
||||||
public function fetchEntities(bool $recursive = false): DatabaseEntityQuery {
|
public function fetchEntities(bool $recursive = false): DatabaseEntityQuery {
|
||||||
|
|
||||||
$this->fetchSubEntities = ($recursive ? self::FETCH_RECURSIVE : self::FETCH_DIRECT);
|
$this->fetchSubEntities = ($recursive ? self::FETCH_RECURSIVE : self::FETCH_DIRECT);
|
||||||
@ -108,6 +108,12 @@ class DatabaseEntityQuery extends Select {
|
|||||||
private function fetchRelation(string $propertyName, string $tableName, DatabaseEntityHandler $src, DatabaseEntityHandler $relationHandler,
|
private function fetchRelation(string $propertyName, string $tableName, DatabaseEntityHandler $src, DatabaseEntityHandler $relationHandler,
|
||||||
bool $recursive = false, string $relationColumnPrefix = "", array &$visited = []) {
|
bool $recursive = false, string $relationColumnPrefix = "", array &$visited = []) {
|
||||||
|
|
||||||
|
|
||||||
|
$property = $src->getProperty($propertyName);
|
||||||
|
if (DatabaseEntityHandler::getAttribute($property, NoFetch::class)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$relIndex = count($visited);
|
$relIndex = count($visited);
|
||||||
if (in_array($relationHandler->getTableName(), $visited)) {
|
if (in_array($relationHandler->getTableName(), $visited)) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user