{"record":{"id":"59de944b05e7f0b4","repo":"n8n-io/n8n","slug":"you-cannot-update-relations-of-multiple-entities-w","errorCode":null,"errorMessage":"You cannot update relations of multiple entities with the same related object. Provide a single entity into .of method.","messagePattern":"You cannot update relations of multiple entities with the same related object\\. Provide a single entity into \\.of method\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/query-builder/RelationUpdater.ts","lineNumber":87,"sourceCode":"\t\t\t\t\tparameters[parameterName] = ObjectUtils.isObject(of)\n\t\t\t\t\t\t? column.referencedColumn!.getEntityValue(of)\n\t\t\t\t\t\t: of;\n\t\t\t\t\tconditions.push(`${column.propertyPath} = :${parameterName}`);\n\t\t\t\t});\n\t\t\t});\n\t\t\tconst condition = conditions.map((str) => '(' + str + ')').join(' OR ');\n\t\t\tif (!condition) return;\n\n\t\t\tawait this.queryBuilder\n\t\t\t\t.createQueryBuilder()\n\t\t\t\t.update(relation.inverseEntityMetadata.target)\n\t\t\t\t.set(updateSet)\n\t\t\t\t.where(condition)\n\t\t\t\t.setParameters(parameters)\n\t\t\t\t.execute();\n\t\t} else if (relation.isOneToOneNotOwner || relation.isOneToMany) {\n\t\t\tif (Array.isArray(this.expressionMap.of))\n\t\t\t\tthrow new TypeORMError(\n\t\t\t\t\t`You cannot update relations of multiple entities with the same related object. Provide a single entity into .of method.`,\n\t\t\t\t);\n\n\t\t\tconst of = this.expressionMap.of;\n\t\t\tconst updateSet = relation.inverseRelation!.joinColumns.reduce((updateSet, joinColumn) => {\n\t\t\t\tconst relationValue = ObjectUtils.isObject(of)\n\t\t\t\t\t? joinColumn.referencedColumn!.getEntityValue(of)\n\t\t\t\t\t: of;\n\t\t\t\tjoinColumn.setEntityValue(updateSet, relationValue);\n\t\t\t\treturn updateSet;\n\t\t\t}, {} as any);\n\n\t\t\tif (!value || (Array.isArray(value) && !value.length)) return;\n\n\t\t\tawait this.queryBuilder\n\t\t\t\t.createQueryBuilder()\n\t\t\t\t.update(relation.inverseEntityMetadata.target)\n\t\t\t\t.set(updateSet)","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/query-builder/RelationUpdater.ts#L69-L105","documentation":"In RelationUpdater.update for isOneToOneNotOwner || isOneToMany branches, TypeORM throws TypeORMError if this.expressionMap.of is an array. The inverse-side update strategy writes the parent's FK value into the related rows; applying the same value to multiple parents is ambiguous, so a single parent is required.","triggerScenarios":"qb.relation(User,'photos').of([user1, user2]).set(photo) or .add(photo) — the parent side is plural for a one-to-many/inverse-one-to-one relation.","commonSituations":"Bulk helpers that pass arrays uniformly to all relation calls; refactoring a single-parent call into a loop but accidentally passing the array to .of.","solutions":["Loop and call per-parent: for (const u of users) await qb.relation(User,'photos').of(u).add(photo).","Restructure as a direct update on the inverse entity with an In(...) condition when bulk is required.","Validate that .of receives a single object before constructing the relation call."],"exampleFix":"// before\nawait qb.relation(User,'photos').of(users).set(photo); // users is an array\n// after\nfor (const u of users) await qb.relation(User,'photos').of(u).set(photo);","handlingStrategy":"validation","validationCode":"function requireSingleOf(qb: any, parent: unknown) {\n  if (Array.isArray(parent)) throw new Error('One-to-many/inverse-one-to-one update requires a single parent in .of()');\n  qb.of(parent);\n}","typeGuard":"function isSingleParent(value: unknown): boolean { return !Array.isArray(value) && value != null; }","tryCatchPattern":null,"preventionTips":["Type helper signatures so .of only accepts a single entity for one-to-many/inverse-one-to-one relations.","Bulk-update via direct manager.update(target, In(ids), partial) instead of relation API."],"tags":["typeorm","relation-updater","one-to-many","bulk"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}