updated repo query schema, repo and withbuilder validation, and reworked relation with building

This commit is contained in:
dswbx
2025-01-16 13:22:15 +01:00
parent 5343d0bd9d
commit 37a65bcaf6
10 changed files with 285 additions and 89 deletions

View File

@@ -1,4 +1,5 @@
import { type Static, Type } from "core/utils";
import type { ExpressionBuilder } from "kysely";
import type { Entity, EntityManager } from "../entities";
import { NumberField, TextField } from "../fields";
import type { RepoQuery } from "../server/data-query-impl";
@@ -87,11 +88,19 @@ export class PolymorphicRelation extends EntityRelation<typeof PolymorphicRelati
};
}
buildWith(entity: Entity, qb: KyselyQueryBuilder, jsonFrom: KyselyJsonFrom) {
buildWith(entity: Entity) {
const { other, whereLhs, reference, entityRef, otherRef } = this.queryInfo(entity);
const limit = other.cardinality === 1 ? 1 : 5;
return qb.select((eb) =>
return (eb: ExpressionBuilder<any, any>) =>
eb
.selectFrom(other.entity.name)
.select(other.entity.getSelect(other.entity.name))
.where(whereLhs, "=", reference)
.whereRef(entityRef, "=", otherRef)
.limit(limit);
/*return qb.select((eb) =>
jsonFrom(
eb
.selectFrom(other.entity.name)
@@ -100,7 +109,7 @@ export class PolymorphicRelation extends EntityRelation<typeof PolymorphicRelati
.whereRef(entityRef, "=", otherRef)
.limit(limit)
).as(other.reference)
);
);*/
}
override isListableFor(entity: Entity): boolean {