(
field: string | RawQueryFragment | NativeQueryBuilder | QueryBuilder,
alias: string,
cond: Dictionary,
type: JoinType,
path?: string,
schema?: string,
subquery?: string,
)
| 3007 | } |
| 3008 | |
| 3009 | private joinReference( |
| 3010 | field: string | RawQueryFragment | NativeQueryBuilder | QueryBuilder, |
| 3011 | alias: string, |
| 3012 | cond: Dictionary, |
| 3013 | type: JoinType, |
| 3014 | path?: string, |
| 3015 | schema?: string, |
| 3016 | subquery?: string, |
| 3017 | ): { prop: EntityProperty<Entity>; key: string } { |
| 3018 | this.ensureNotFinalized(); |
| 3019 | |
| 3020 | if (typeof field === 'object') { |
| 3021 | const prop = { |
| 3022 | name: '__subquery__', |
| 3023 | kind: ReferenceKind.MANY_TO_ONE, |
| 3024 | } as EntityProperty; |
| 3025 | |
| 3026 | if (field instanceof QueryBuilder) { |
| 3027 | prop.type = Utils.className(field.mainAlias.entityName); |
| 3028 | prop.targetMeta = field.mainAlias.meta!; |
| 3029 | field = field.getNativeQuery(); |
| 3030 | } |
| 3031 | |
| 3032 | if (isRaw(field)) { |
| 3033 | field = this.platform.formatQuery(field.sql, field.params); |
| 3034 | } |
| 3035 | |
| 3036 | const key = `${this.alias}.${prop.name}#${alias}`; |
| 3037 | this.#state.joins[key] = { |
| 3038 | prop, |
| 3039 | alias, |
| 3040 | type, |
| 3041 | cond, |
| 3042 | schema, |
| 3043 | subquery: field.toString(), |
| 3044 | ownerAlias: this.alias, |
| 3045 | } as any; |
| 3046 | |
| 3047 | return { prop, key }; |
| 3048 | } |
| 3049 | |
| 3050 | if (!subquery && type.includes('lateral')) { |
| 3051 | throw new Error(`Lateral join can be used only with a sub-query.`); |
| 3052 | } |
| 3053 | |
| 3054 | const [fromAlias, fromField] = this.helper.splitField(field as EntityKey<Entity>); |
| 3055 | const q = (str: string) => `'${str}'`; |
| 3056 | |
| 3057 | if (!this.#state.aliases[fromAlias]) { |
| 3058 | throw new Error( |
| 3059 | `Trying to join ${q(fromField)} with alias ${q(fromAlias)}, but ${q(fromAlias)} is not a known alias. Available aliases are: ${Object.keys(this.#state.aliases).map(q).join(', ')}.`, |
| 3060 | ); |
| 3061 | } |
| 3062 | |
| 3063 | const entityName = this.#state.aliases[fromAlias].entityName; |
| 3064 | const meta = this.metadata.get(entityName); |
| 3065 | const prop = meta.properties[fromField]; |
| 3066 |
no test coverage detected