- More work done on Update, Insert and Delete clause

- Added TOP property to select and delete to fit MSSQL limit's term.
- Added a new interface allowing object's manipulation on save() and load() queries
This commit is contained in:
Dave Mc Nicoll committed 2020-02-07 16:36:38 -05:00
1 parent 3dc82b1f0d
commit 2f43fb4559
13 files changed
+169 -58

No files matched your search

+28 -7
View File
@@ -22,12 +22,17 @@ trait EntityTrait {
*/
protected array $unmatchedEntityDatasetFields = [];
/**
* @Ignore
*/
public array $datasetSource = [];
/**
* @Ignore
*/
public function __get(string $name)
{
$entityResolver= $this->resolveEntity();
$entityResolver = $this->resolveEntity();
# Resolve relations here if one is called
if ( null !== ( $relation = $entityResolver->searchFieldAnnotation($name, new Relation() ) ) ) {
@@ -80,13 +85,15 @@ trait EntityTrait {
*/
public function entityFillFromDataset(iterable $dataset) : self
{
$fields = $this->resolveEntity();
$loaded = $this->isLoaded();
$entityResolver = $this->resolveEntity();
foreach($dataset as $key => $value) {
$field = $fields->field(strtolower($key), EntityResolver::KEY_COLUMN_NAME, false) ?? null;
$field = $entityResolver->field(strtolower($key), EntityResolver::KEY_COLUMN_NAME, false) ?? null;
if ( $field === null ) {
$field = $fields->field($key, EntityResolver::KEY_ENTITY_NAME, false);
$field = $entityResolver->field($key, EntityResolver::KEY_ENTITY_NAME, false);
}
if ( $field === null ) {
@@ -109,6 +116,15 @@ trait EntityTrait {
elseif ( ! $field['builtin'] ) {
$this->{$field['name']} = Ulmus::instanciateObject($field['type'], [ $value ]);
}
# Keeping original data to diff on UPDATE query
if ( ! $loaded ) {
#if ( $field !== null ) {
# $annotation = $entityResolver->searchFieldAnnotation($field['name'], new Field() );
# $this->datasetSource[$annotation ? $annotation->name : $field['name']] = $dataset; # <--------- THIS TO FIX !!!!!!
#}
$this->datasetSource = array_change_key_case($dataset, \CASE_LOWER);
}
}
return $this;
@@ -119,16 +135,21 @@ trait EntityTrait {
return $this->entityFillFromDataset($dataset);
}
public function entityGetDataset() : array
{
public function entityGetDataset(bool $returnSource = false) : array
{
if ( $returnSource ) {
return $this->datasetSource;
}
$dataset = [];
$entityResolver = $this->resolveEntity();
foreach($entityResolver->fieldList() as $key => $field) {
$annotation = $entityResolver->searchFieldAnnotation($key, new Field() );
if ( isset($this->$key) ) {
$dataset[ $annotation->name ?? $key ] = $this->$key;
$dataset[ $annotation->name ?? $key ] = is_object($this->$key) ? Ulmus::convertObject($this->$key) : $this->$key;
}
elseif ( $field['nullable'] ) {
$dataset[ $annotation->name ?? $key ] = null;