From 8e28aac4c2e73a7efdf2bbbec83e8c1e617279a0 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 25 Oct 2023 11:50:37 +0200 Subject: [PATCH] [jOOQ/jOOQ#13639] Handle to-many paths in DML --- .../main/java/org/jooq/impl/TableFieldImpl.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/TableFieldImpl.java b/jOOQ/src/main/java/org/jooq/impl/TableFieldImpl.java index 752d0f7c34..c8e40523f9 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableFieldImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableFieldImpl.java @@ -56,6 +56,7 @@ import java.util.stream.Stream; import org.jooq.Binding; import org.jooq.Clause; import org.jooq.Comment; +import org.jooq.Condition; import org.jooq.Context; import org.jooq.DMLQuery; import org.jooq.DataType; @@ -183,17 +184,23 @@ implements // DML statement can be generated normally. && (!ctx.subquery() || root.equals(ctx.data(SimpleDataKey.DATA_DML_TARGET_TABLE))) ) { + TableImpl t = (TableImpl) table; - // [#7508] MySQL supports UPDATE .. JOIN, so the default implicit - // JOIN emulation works out of the box. - if (ctx.topLevelForLanguageContext() instanceof Update && !NO_SUPPORT_UPDATE_JOIN.contains(ctx.dialect())) { + // [#7508] MySQL supports UPDATE .. JOIN, so the default implicit + // JOIN emulation works out of the box. + // [#13639] But do this for to-one paths only + if (ctx.topLevelForLanguageContext() instanceof Update + && !NO_SUPPORT_UPDATE_JOIN.contains(ctx.dialect()) + && t.childPath != null) { accept1(ctx); } else { - TableImpl t = (TableImpl) table; Table parent = t.alias.wrapped; Field parentField = parent.field(this); - ctx.visit(DSL.field(select(parentField).from(parent).where(JoinTable.onKey0(t.childPath, t.path, parent)))); + Condition c = t.childPath != null + ? JoinTable.onKey0(t.childPath, t.path, parent) + : JoinTable.onKey0(t.parentPath.getForeignKey(), parent, t.path); + ctx.visit(DSL.field(select(parentField).from(parent).where(c))); } } else