- 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

+17 -8
View File
@@ -39,7 +39,9 @@ class Repository
$this->alias = $alias;
$this->entityResolver = Ulmus::resolveEntity($entity);
$this->adapter = $adapter ?? $this->entityResolver->databaseAdapter();
$this->queryBuilder = Ulmus::queryBuilder($entity);
$queryBuilder = $this->adapter->adapter()->queryBuilderClass();
$this->queryBuilder = new $queryBuilder();
}
public function __clone()
@@ -49,7 +51,7 @@ class Repository
public function loadOne() : ? object
{
return $this->limit(1)->selectSqlQuery()->collectionFromQuery()[0] ?? null;
return $this->limit(1)->selectSqlQuery()->collectionFromQuery()[0];
}
public function loadOneFromField($field, $value) : ? object
@@ -606,7 +608,7 @@ class Repository
$isRelation = ( $annotation instanceof Relation ) || ($annotation instanceof Attribute\Property\Relation);
if ($isRelation && ( $annotation->normalizeType() === 'manytomany' )) {
if ($isRelation && ( $annotation->isManyToMany() )) {
throw new Exception("Many-to-many relation can not be preloaded within joins.");
}
@@ -618,10 +620,12 @@ class Repository
foreach($entity::resolveEntity()->fieldList(Common\EntityResolver::KEY_COLUMN_NAME, true) as $key => $field) {
if ( null === $entity::resolveEntity()->searchFieldAnnotation($field['name'], [ Attribute\Property\Relation\Ignore::class, RelationIgnore::class ]) ) {
$escAlias = $this->escapeIdentifier($alias);
$fieldName = $this->escapeIdentifier($key);
$name = $entity::resolveEntity()->searchFieldAnnotation($field['name'], [ Attribute\Property\Field::class, Field::class ])->name ?? $field['name'];
$this->select("$escAlias.$key as $alias\${$name}");
$this->select("$escAlias.$fieldName as $alias\${$name}");
}
}
@@ -761,7 +765,8 @@ class Repository
}
foreach ($where as $condition) {
$repository->where($condition->field, is_callable($condition->value) ? call_user_func_array($condition->value, [$this]) : $condition->getValue(), $condition->operator, $condition->condition);
# $repository->where($condition->field, is_callable($condition->value) ? call_user_func_array($condition->value, [$this]) : $condition->getValue(), $condition->operator, $condition->condition);
$repository->where($condition->field, $condition->getValue($this), $condition->operator, $condition->condition);
}
foreach ($order as $item) {
@@ -778,17 +783,21 @@ class Repository
$values[] = is_callable($field) ? $field($item) : $item->$entityProperty;
}
$values = array_unique($values);
$repository->where($key, $values);
$results = call_user_func([ $repository, $relation->function() ]);
$results = $repository->loadAll();
if ($relation->isOneToOne()) {
$item->$name = $results ?: new $baseEntity();
foreach ($collection as $item) {
$item->$name = $results->searchOne($item->$entityProperty, $property) ?: new $baseEntity();
}
}
elseif ($relation->isOneToMany()) {
foreach ($collection as $item) {
$item->$name = $baseEntity::entityCollection();
$item->$name->mergeWith($results->filtersCollection(fn($e) => $e->$property === $item->$entityProperty));
$item->$name->mergeWith($results->searchAll($item->$entityProperty, $property));
}
}
}