Skip to content

Commit 0b27dd5

Browse files
bahusoidhazzik
authored andcommitted
Allow using ON instead of WITH in hql (#2032)
1 parent 70e25a3 commit 0b27dd5

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

src/NHibernate.Test/Async/Hql/EntityJoinHqlTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ public async Task CanJoinNotAssociatedEntityAsync()
4747
}
4848
}
4949

50+
[Test]
51+
public async Task CanJoinNotAssociatedEntity_OnKeywordAsync()
52+
{
53+
using (var sqlLog = new SqlLogSpy())
54+
using (var session = OpenSession())
55+
{
56+
EntityComplex entityComplex =
57+
await (session
58+
.CreateQuery("select ex " +
59+
"from EntityWithNoAssociation root " +
60+
"left join EntityComplex ex on root.Complex1Id = ex.Id")
61+
.SetMaxResults(1)
62+
.UniqueResultAsync<EntityComplex>());
63+
64+
Assert.That(entityComplex, Is.Not.Null);
65+
Assert.That(NHibernateUtil.IsInitialized(entityComplex), Is.True);
66+
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
67+
}
68+
}
69+
5070
[Test]
5171
public async Task EntityJoinForCompositeKeyAsync()
5272
{

src/NHibernate.Test/Hql/EntityJoinHqlTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ public void CanJoinNotAssociatedEntity()
3636
}
3737
}
3838

39+
[Test]
40+
public void CanJoinNotAssociatedEntity_OnKeyword()
41+
{
42+
using (var sqlLog = new SqlLogSpy())
43+
using (var session = OpenSession())
44+
{
45+
EntityComplex entityComplex =
46+
session
47+
.CreateQuery("select ex " +
48+
"from EntityWithNoAssociation root " +
49+
"left join EntityComplex ex on root.Complex1Id = ex.Id")
50+
.SetMaxResults(1)
51+
.UniqueResult<EntityComplex>();
52+
53+
Assert.That(entityComplex, Is.Not.Null);
54+
Assert.That(NHibernateUtil.IsInitialized(entityComplex), Is.True);
55+
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
56+
}
57+
}
58+
3959
[Test]
4060
public void EntityJoinForCompositeKey()
4161
{

src/NHibernate/Hql/Ast/ANTLR/Hql.g

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ fromJoin
259259
260260
withClause
261261
: WITH^ logicalExpression
262+
| ON logicalExpression
263+
// it's really just a WITH clause, so treat it as such...
264+
-> ^(WITH["with"] logicalExpression)
262265
;
263266

264267
fromRange

src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,7 @@ public bool IsComparativeExpressionClause
11041104
{
11051105
get
11061106
{
1107-
// Note: once we add support for "JOIN ... ON ...",
1108-
// the ON clause needs to get included here
1107+
//Note: "JOIN ... ON ..." case is treated as "JOIN ... WITH ..." by parser
11091108
return CurrentClauseType == WHERE ||
11101109
CurrentClauseType == WITH ||
11111110
IsInCase;

0 commit comments

Comments
 (0)