Skip to content

Commit f3d7c92

Browse files
iss-182: add support for delete with Join
1 parent 50382fa commit f3d7c92

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

QueryBuilder/Compilers/Compiler.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,32 @@ protected virtual SqlResult CompileDeleteQuery(Query query)
263263
throw new InvalidOperationException("Invalid table expression");
264264
}
265265

266+
var joins = CompileJoins(ctx);
267+
266268
var where = CompileWheres(ctx);
267269

268270
if (!string.IsNullOrEmpty(where))
269271
{
270272
where = " " + where;
271273
}
272274

273-
ctx.RawSql = $"DELETE FROM {table}{where}";
275+
if (string.IsNullOrEmpty(joins))
276+
{
277+
ctx.RawSql = $"DELETE FROM {table}{where}";
278+
}
279+
else
280+
{
281+
// check if we have alias
282+
if (fromClause is FromClause && !string.IsNullOrEmpty(fromClause.Alias))
283+
{
284+
ctx.RawSql = $"DELETE {Wrap(fromClause.Alias)} FROM {table} {joins}{where}";
285+
}
286+
else
287+
{
288+
ctx.RawSql = $"DELETE {table} FROM {table} {joins}{where}";
289+
}
290+
291+
}
274292

275293
return ctx;
276294
}

0 commit comments

Comments
 (0)