Skip to content

Skip table group join processing for implicit join #3106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections;
using NUnit.Framework;
using System.Linq;
using NHibernate.Linq;

namespace NHibernate.Test.SubclassFilterTest
{
Expand Down Expand Up @@ -107,6 +108,35 @@ public async Task FiltersWithSubclassAsync()
s.Close();
}

[Test]
public async Task FilterCollectionWithSubclass1Async()
{
using var s = OpenSession();
using var t = s.BeginTransaction();
await (PrepareTestDataAsync(s));

s.EnableFilter("minionsWithManager");

var employees = await (s.Query<Employee>().Where(x => x.Minions.Any()).ToListAsync());
Assert.That(employees.Count, Is.EqualTo(1));
Assert.That(employees[0].Minions.Count, Is.EqualTo(2));
}

[KnownBug("GH-3079: Collection filter on subclass columns")]
[Test]
public async Task FilterCollectionWithSubclass2Async()
{
using var s = OpenSession();
using var t = s.BeginTransaction();
await (PrepareTestDataAsync(s));

s.EnableFilter("minionsRegion").SetParameter("userRegion", "US");

var employees = await (s.Query<Employee>().Where(x => x.Minions.Any()).ToListAsync());
Assert.That(employees.Count, Is.EqualTo(1));
Assert.That(employees[0].Minions.Count, Is.EqualTo(1));
}

private static async Task PrepareTestDataAsync(ISession s, CancellationToken cancellationToken = default(CancellationToken))
{
Employee john = new Employee("John Doe");
Expand Down Expand Up @@ -147,4 +177,4 @@ public async Task FiltersWithSubclassAsync()
await (s.FlushAsync(cancellationToken));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,35 @@ public void FiltersWithSubclass()
s.Close();
}

[Test]
public void FilterCollectionWithSubclass1()
{
using var s = OpenSession();
using var t = s.BeginTransaction();
PrepareTestData(s);

s.EnableFilter("minionsWithManager");

var employees = s.Query<Employee>().Where(x => x.Minions.Any()).ToList();
Assert.That(employees.Count, Is.EqualTo(1));
Assert.That(employees[0].Minions.Count, Is.EqualTo(2));
}

[KnownBug("GH-3079: Collection filter on subclass columns")]
[Test]
public void FilterCollectionWithSubclass2()
{
using var s = OpenSession();
using var t = s.BeginTransaction();
PrepareTestData(s);

s.EnableFilter("minionsRegion").SetParameter("userRegion", "US");

var employees = s.Query<Employee>().Where(x => x.Minions.Any()).ToList();
Assert.That(employees.Count, Is.EqualTo(1));
Assert.That(employees[0].Minions.Count, Is.EqualTo(1));
}

private static void PrepareTestData(ISession s)
{
Employee john = new Employee("John Doe");
Expand Down Expand Up @@ -135,4 +164,4 @@ private static void PrepareTestData(ISession s)
s.Flush();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<set name="Minions" inverse="true" lazy="true" cascade="all">
<key column="mgr_id"/>
<one-to-many class="Employee"/>
<filter name="minionsWithManager" condition="mgr_id is not null"/>
<filter name="minionsRegion" condition="Region = :userRegion"/>
</set>
</joined-subclass>

Expand All @@ -36,4 +38,8 @@
<filter-def name="region">
<filter-param name="userRegion" type="string"/>
</filter-def>
</hibernate-mapping>
<filter-def name="minionsRegion">
<filter-param name="userRegion" type="string"/>
</filter-def>
<filter-def name="minionsWithManager"/>
</hibernate-mapping>
2 changes: 1 addition & 1 deletion src/NHibernate/Engine/JoinSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ internal JoinFragment ToJoinFragment(
last = join.Joinable;
}

if (rootJoinable == null && TableGroupJoinHelper.ProcessAsTableGroupJoin(joins, withClauses, includeAllSubclassJoins, joinFragment, alias => IsIncluded(alias), factory))
if (rootJoinable == null && !IsThetaStyle && TableGroupJoinHelper.ProcessAsTableGroupJoin(joins, withClauses, includeAllSubclassJoins, joinFragment, alias => IsIncluded(alias), factory))
{
return joinFragment;
}
Expand Down