- WIP on SQLite Adapter and migration

This commit is contained in:
mcndave committed 2023-03-27 18:38:31 +00:00
1 parent cee978ecfd
commit 9514a46ae7
14 files changed
+98 -40

No files matched your search

+6 -6
View File
@@ -9,7 +9,7 @@ class Relation {
public function __construct(
public Relation\RelationTypeEnum|string $type,
public \Stringable|string|array $key = "",
public null|\Closure $generateKey = null,
public null|\Closure|array $generateKey = null,
public null|\Stringable|string|array $foreignKey = null,
public null|\Stringable|string|array $foreignField = null,
public array $foreignKeys = [],
@@ -20,7 +20,7 @@ class Relation {
public null|\Stringable|string|array $field = null,
public null|string $entity = null,
public null|string $join = null,
public string $function = "loadAll",
public null|string $function = null,
) {
$this->key = Attribute::handleArrayField($this->key);
$this->foreignKey = Attribute::handleArrayField($this->foreignKey);
@@ -54,17 +54,17 @@ class Relation {
public function isOneToOne() : bool
{
return $this->type === Relation\RelationTypeEnum::oneToOne || $this->normalizeType() === 'onetoone';
return $this->type instanceof Relation\RelationTypeEnum ? $this->type === Relation\RelationTypeEnum::oneToOne : $this->normalizeType() === 'onetoone';
}
public function isOneToMany() : bool
{
return $this->type === Relation\RelationTypeEnum::oneToMany || $this->normalizeType() === 'onetomany';
return $this->type instanceof Relation\RelationTypeEnum ? $this->type === Relation\RelationTypeEnum::oneToMany : $this->normalizeType() === 'onetomany';
}
public function isManyToMany() : bool
{
return $this->type === Relation\RelationTypeEnum::manyToMany || $this->normalizeType() === 'manytomany';
return $this->type instanceof Relation\RelationTypeEnum ? $this->type === Relation\RelationTypeEnum::manyToMany : $this->normalizeType() === 'manytomany';
}
public function function() : string
@@ -73,7 +73,7 @@ class Relation {
return $this->function;
}
elseif ($this->isOneToOne()) {
return 'load';
return 'loadOne';
}
return 'loadAll';
+11 -1
View File
@@ -13,13 +13,23 @@ class Where {
public string $operator = Query\Where::OPERATOR_EQUAL,
public string $condition = Query\Where::CONDITION_AND,
public string|\Stringable|array|null $fieldValue = null,
public null|array $generateValue = null,
) {
$this->field = Attribute::handleArrayField($field);
$this->fieldValue = Attribute::handleArrayField($fieldValue);
}
public function getValue() : mixed
public function getValue(/* null|EntityInterface */ $entity = null) : mixed
{
if ($this->generateValue) {
if ($entity) {
return call_user_func_array($this->generateValue, [ $entity ]);
}
else {
throw new \Exception(sprintf("Could not generate value from non-instanciated entity for field %s.", (string) $this->field));
}
}
return $this->fieldValue ?? $this->value;
}
}