- WIP on Ulmus -- new use case showed up, modification were needed.

This commit is contained in:
Dave Mc Nicoll committed 2019-12-10 15:27:45 -05:00
1 parent 1b051f923e
commit b589ba3c2b
5 files changed
+28 -13

No files matched your search

+14 -4
View File
@@ -11,6 +11,10 @@ use Ulmus\Annotation\Property\{ Field, Relation, OrderBy, Where, };
use Ulmus\Annotation\Property\Field\{ Id, ForeignKey, CreatedAt, UpdatedAt, };
trait EntityTrait {
protected bool $strictEntityFieldsDeclaration = true;
protected array $unmatchedEntityDatasetFields = [];
/**
* @Ignore
@@ -20,11 +24,17 @@ trait EntityTrait {
$fields = Ulmus::resolveEntity(static::class);
foreach($dataset as $key => $value) {
if ( null === $field = $fields->field($key, EntityResolver::KEY_COLUMN_NAME) ?? null ) {
throw new \Exception("Field `$key` can not be found within your entity ".static::class);
$key = strtolower($key);
if ( null === $field = $fields->field($key, EntityResolver::KEY_COLUMN_NAME, false) ?? null ) {
if ($this->strictEntityFieldsDeclaration ) {
throw new \Exception("Field `$key` can not be found within your entity ".static::class);
}
else {
$this->unmatchedEntityDatasetFields[$key] = $value;
}
}
if ( is_null($value) ) {
elseif ( is_null($value) ) {
$this->{$field['name']} = null;
}
elseif ( $field['type'] === 'array' ) {