MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / fromRawTable

Method fromRawTable

packages/sql/src/query/QueryBuilder.ts:4315–4337  ·  view source on GitHub ↗
(tableName: string, aliasName?: string)

Source from the content-addressed store, hash-verified

4313 }
4314
4315 private fromRawTable(tableName: string, aliasName?: string): void {
4316 aliasName ??= this.#state.mainAlias?.aliasName ?? this.getNextAlias(tableName);
4317 // If the raw table name matches a CTE registered via `.with()` from a typed QueryBuilder,
4318 // reuse the source entity meta so relation joins (`leftJoinAndSelect` etc.) keep working.
4319 const cteMeta = this.#state.ctes.find(c => c.name === tableName)?.meta;
4320 let meta: EntityMetadata<Entity>;
4321
4322 if (cteMeta) {
4323 meta = cteMeta as EntityMetadata<Entity>;
4324 } else {
4325 meta = new EntityMetadata<Entity>({ className: tableName, collection: tableName });
4326 meta.root = meta;
4327 }
4328
4329 this.#state.mainAlias = {
4330 aliasName,
4331 entityName: (cteMeta?.className ?? tableName) as unknown as EntityName<Entity>,
4332 meta,
4333 rawTableName: tableName,
4334 };
4335 this.#state.aliases[aliasName] = this.#state.mainAlias;
4336 this.#helper = this.createQueryBuilderHelper();
4337 }
4338
4339 private createQueryBuilderHelper(): QueryBuilderHelper {
4340 return new QueryBuilderHelper(

Callers 1

fromMethod · 0.95

Calls 3

getNextAliasMethod · 0.95
findMethod · 0.65

Tested by

no test coverage detected