(aliasOrTargetEntity: string | EntityName<T>, alias?: EntityKey<T>)
| 2707 | as<T>(targetEntity: EntityName<T>, alias: EntityKey<T>): NativeQueryBuilder; |
| 2708 | |
| 2709 | as<T>(aliasOrTargetEntity: string | EntityName<T>, alias?: EntityKey<T>): NativeQueryBuilder { |
| 2710 | const qb = this.getNativeQuery(); |
| 2711 | let finalAlias = aliasOrTargetEntity as string; |
| 2712 | |
| 2713 | /* v8 ignore next */ |
| 2714 | if (typeof aliasOrTargetEntity === 'string' && aliasOrTargetEntity.includes('.')) { |
| 2715 | throw new Error( |
| 2716 | 'qb.as(alias) no longer supports target entity name prefix, use qb.as(TargetEntity, key) signature instead', |
| 2717 | ); |
| 2718 | } |
| 2719 | |
| 2720 | if (alias) { |
| 2721 | const meta = this.metadata.get(aliasOrTargetEntity as EntityName<T>); |
| 2722 | /* v8 ignore next */ |
| 2723 | finalAlias = meta.properties[alias]?.fieldNames[0] ?? alias; |
| 2724 | } |
| 2725 | |
| 2726 | qb.as(finalAlias); |
| 2727 | |
| 2728 | // tag the instance, so it is possible to detect it easily |
| 2729 | Object.defineProperty(qb, '__as', { enumerable: false, value: finalAlias }); |
| 2730 | |
| 2731 | return qb; |
| 2732 | } |
| 2733 | |
| 2734 | /** |
| 2735 | * Combines the current query with one or more other queries using `UNION ALL`. |
no test coverage detected