(meta: EntityMetadata)
| 4246 | } |
| 4247 | |
| 4248 | private wrapModifySubQuery(meta: EntityMetadata): void { |
| 4249 | const subQuery = this.clone(); |
| 4250 | subQuery.#state.finalized = true; |
| 4251 | |
| 4252 | // wrap one more time to get around MySQL limitations |
| 4253 | // https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause |
| 4254 | const subSubQuery = this.platform.createNativeQueryBuilder(); |
| 4255 | const method = this.#state.flags.has(QueryFlag.UPDATE_SUB_QUERY) ? 'update' : 'delete'; |
| 4256 | const schema = this.getSchema(this.mainAlias); |
| 4257 | const pks = this.prepareFields(meta.primaryKeys, 'sub-query', schema) as string[]; |
| 4258 | this.#state.cond = {}; // otherwise we would trigger validation error |
| 4259 | this.#state.joins = {}; // included in the subquery |
| 4260 | subSubQuery.select(pks).from(subQuery.as(this.mainAlias.aliasName)); |
| 4261 | |
| 4262 | const { sql, params } = subSubQuery.compile(); |
| 4263 | ((this[method] as (data?: unknown) => RunQueryBuilder<Entity>)(this.#state.data).where as any)({ |
| 4264 | [Utils.getPrimaryKeyHash(meta.primaryKeys)]: { $in: raw(sql, params) }, |
| 4265 | }); |
| 4266 | } |
| 4267 | |
| 4268 | private getSchema(alias: Alias<any>): string | undefined { |
| 4269 | const { meta } = alias; |
no test coverage detected