- WIP on Migration of MsSQL

This commit is contained in:
Dave Mc Nicoll committed 2025-05-21 18:46:34 +00:00
1 parent c54de30069
commit fb4985160a
17 files changed
+252 -175

No files matched your search

+37 -24
View File
@@ -438,19 +438,19 @@ class Repository implements RepositoryInterface
}
if ( $attribute ) {
$alias = $attribute->alias ?? $item;
$attribute->alias ??= $item;
$entity = $attribute->entity ?? $this->entityResolver->getPropertyEntityType($item);
$attribute->entity ??= $this->entityResolver->getPropertyEntityType($item);
foreach($entity::resolveEntity()->fieldList(Common\EntityResolver::KEY_COLUMN_NAME, true) as $key => $field) {
if ( null === $entity::resolveEntity()->searchFieldAnnotation($field->name, [ Relation\Ignore::class ]) ) {
$escAlias = $this->escapeIdentifier($alias);
foreach($attribute->entity::resolveEntity()->fieldList(Common\EntityResolver::KEY_COLUMN_NAME, true) as $key => $field) {
if ( null === $attribute->entity::resolveEntity()->searchFieldAnnotation($field->name, [ Relation\Ignore::class ]) ) {
$escAlias = $this->escapeIdentifier($attribute->alias);
$fieldName = $this->escapeIdentifier($key);
$name = $entity::resolveEntity()->searchFieldAnnotation($field->name, [ Field::class ])->name ?? $field->name;
$name = $attribute->entity::resolveEntity()->searchFieldAnnotation($field->name, [ Field::class ])->name ?? $field->name;
if ($canSelect) {
$this->select("$escAlias.$fieldName as $alias\${$name}");
$this->select("$escAlias.$fieldName as {$attribute->alias}\${$name}");
}
}
}
@@ -459,15 +459,15 @@ class Repository implements RepositoryInterface
if ( ! in_array(WithOptionEnum::SkipWhere, $options)) {
foreach($this->entityResolver->searchFieldAnnotationList($item, [ Where::class ] ) as $condition) {
if ( is_object($condition->field) && ( $condition->field->entityClass !== $entity ) ) {
$this->where(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->getValue(), $condition->operator);
if ( is_object($condition->field) && ( $condition->field->entityClass !== $attribute->entity ) ) {
$this->where(is_object($condition->field) ? $condition->field : $attribute->entity::field($condition->field), $condition->getValue(), $condition->operator);
}
}
}
if ( ! in_array(WithOptionEnum::SkipHaving, $options)) {
foreach ($this->entityResolver->searchFieldAnnotationList($item, [ Having::class ]) as $condition) {
$this->having(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->getValue(), $condition->operator);
$this->having(is_object($condition->field) ? $condition->field : $attribute->entity::field($condition->field), $condition->getValue(), $condition->operator);
}
}
@@ -480,9 +480,9 @@ class Repository implements RepositoryInterface
$this->close();
$key = is_string($attribute->key) ? $this->entityClass::field($attribute->key) : $attribute->key;
$foreignKey = $this->evalClosure($attribute->foreignKey, $entity, $alias);
$foreignKey = $this->evalClosure($attribute->foreignKey, $attribute->entity, $attribute->alias);
$this->join($isRelation ? "LEFT" : $attribute->type, $entity::resolveEntity()->tableName(), $key, $foreignKey, $alias, function($join) use ($item, $entity, $alias, $options) {
$this->join($isRelation ? "LEFT" : $attribute->type, $attribute->entity::resolveEntity()->tableName(), $key, $attribute->foreignKey($this), $attribute->alias, function($join) use ($item, $attribute, $options) {
if ( ! in_array(WithOptionEnum::SkipJoinWhere, $options)) {
foreach($this->entityResolver->searchFieldAnnotationList($item, [ Where::class ]) as $condition) {
if ( ! is_object($condition->field) ) {
@@ -493,10 +493,10 @@ class Repository implements RepositoryInterface
}
# Adding directly
if ( $field->entityClass === $entity ) {
$field->alias = $alias;
if ( $field->entityClass === $attribute->entity ) {
$field->alias = $attribute->alias;
$join->where(is_object($field) ? $field : $entity::field($field, $alias), $condition->getValue(), $condition->operator);
$join->where(is_object($field) ? $field : $attribute->entity::field($field, $attribute->alias), $condition->getValue(), $condition->operator);
}
}
}
@@ -536,7 +536,7 @@ class Repository implements RepositoryInterface
# Apply FILTER annotation to this too !
foreach(array_filter((array) $fields) as $item) {
if ( $relation = $this->entityResolver->searchFieldAnnotation($item, [ Relation::class ]) ) {
$alias = $relation->alias ?? $item;
$relation->alias ??= $item;
if ( $relation->isManyToMany() ) {
$entity = $relation->bridge;
@@ -545,13 +545,14 @@ class Repository implements RepositoryInterface
extract(Repository\RelationBuilder::relationAnnotations($item, $relation));
$repository->join(Query\Join::TYPE_INNER, $bridgeEntity->tableName(), $relation->bridge::field($relationRelation->key, $relation->bridgeField), $relationRelation->entity::field($relationRelation->foreignKey, $alias), $relation->bridgeField)
$repository->join(Query\Join::TYPE_INNER, $bridgeEntity->tableName(), $relation->bridge::field($relationRelation->key, $relation->bridgeField), $relationRelation->entity::field($relationRelation->foreignKey, $relation->alias), $relation->bridgeField)
->where( $entity::field($bridgeRelation->key, $relation->bridgeField), $entity::field($bridgeRelation->foreignKey, $this->alias))
->selectJsonEntity($relationRelation->entity, $alias)->open();
->selectJsonEntity($relationRelation->entity, $relation->alias)->open();
}
else {
$entity = $relation->entity ?? $this->entityResolver->getPropertyEntityType($name);
$repository = $entity::repository()->selectJsonEntity($entity, $alias)->open();
$relation->entity ??= $this->entityResolver->getPropertyEntityType($name);
$entity = $relation->entity;
$repository = $relation->entity::repository()->selectJsonEntity($entity, $relation->alias)->open();
}
# $relation->isManyToMany() and $repository->selectJsonEntity($relation->bridge, $relation->bridgeField, true);
@@ -560,16 +561,21 @@ class Repository implements RepositoryInterface
$repository->where(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->getValue(), $condition->operator);
}
foreach($this->entityResolver->searchFieldAnnotationList($item, [ Having::class ] ) as $condition) {
$repository->having(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->getValue(), $condition->operator);
}
foreach ($this->entityResolver->searchFieldAnnotationList($item, [ Filter::class ]) as $filter) {
call_user_func_array([$this->entityClass, $filter->method], [$this, $item, true]);
}
$repository->close();
$key = is_string($relation->key) ? $this->entityClass::field($relation->key) : $relation->key;
if (! $relation->isManyToMany() ) {
$foreignKey = is_string($relation->foreignKey) ? $entity::field($relation->foreignKey, $alias) : $relation->foreignKey;
$foreignKey = is_string($relation->foreignKey) ? $entity::field($relation->foreignKey, $relation->alias) : $relation->foreignKey;
$repository->where( $foreignKey, $key);
}
@@ -590,6 +596,7 @@ class Repository implements RepositoryInterface
if (null !== ($relation = $this->entityResolver->searchFieldAnnotation($name, [ Relation::class ] ))) {
$order = $this->entityResolver->searchFieldAnnotationList($name, [ OrderBy::class ]);
$where = $this->entityResolver->searchFieldAnnotationList($name, [ Where::class ]);
$filters = $this->entityResolver->searchFieldAnnotationList($name, [ Filter::class ]);
$baseEntity = $relation->entity ?? $relation->bridge ?? $this->entityResolver->getPropertyEntityType($name);
$baseEntityResolver = $baseEntity::resolveEntity();
@@ -610,6 +617,10 @@ class Repository implements RepositoryInterface
$repository->where($condition->field, $condition->getValue(/* why repository sent here ??? $this */), $condition->operator, $condition->condition);
}
foreach ($filters as $filter) {
call_user_func_array([ $this->entityClass, $filter->method ], [ $repository, $name, true ]);
}
foreach ($order as $item) {
$repository->orderBy($item->field, $item->order);
}
@@ -628,7 +639,8 @@ class Repository implements RepositoryInterface
$repository->where($key, $values);
$results = $repository->loadAll();
$loadMethod = $relation->isOneToOne() ? 'loadAll' : $relation->function();
$results = $repository->{$loadMethod}();
if ($relation->isOneToOne()) {
foreach ($collection as $item) {
@@ -638,7 +650,8 @@ class Repository implements RepositoryInterface
elseif ($relation->isOneToMany()) {
foreach ($collection as $item) {
$item->$name = $baseEntity::entityCollection();
$item->$name->mergeWith($results->searchAll($item->$entityProperty, $property));
$search = $results->searchAll($item->$entityProperty, $property);
$item->$name->mergeWith($search);
}
}
}
@@ -646,7 +659,7 @@ class Repository implements RepositoryInterface
}
## AWAITING THE Closures in constant expression from PHP 8.5 !
protected function evalClosure(\Stringable|string $content, string $entityClass, mixed $alias = self::DEFAULT_ALIAS) : mixed
protected function evalClosure(mixed $content, string $entityClass, mixed $alias = self::DEFAULT_ALIAS) : mixed
{
if (is_string($content)) {
if ( str_starts_with($content, 'fn(') ) {