-
Notifications
You must be signed in to change notification settings - Fork 934
Fix many-to-one disabled filters for entity joins #3048
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
Changes from all commits
10a5d4c
0eb73ae
9f99166
0420362
890a131
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,7 +175,7 @@ internal virtual JoinFragment ToJoinFragment( | |
{ | ||
Join join = joins[i]; | ||
string on = join.AssociationType.GetOnCondition(join.Alias, factory, enabledFilters); | ||
SqlString condition = new SqlString(); | ||
SqlString condition; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Little cleanup by the way. |
||
if (last != null && | ||
IsManyToManyRoot(last) && | ||
((IQueryableCollection)last).ElementType == join.AssociationType) | ||
|
@@ -195,10 +195,17 @@ internal virtual JoinFragment ToJoinFragment( | |
{ | ||
// NH Different behavior : NH1179 and NH1293 | ||
// Apply filters for entity joins and Many-To-One association | ||
var enabledForManyToOne = FilterHelper.GetEnabledForManyToOne(enabledFilters); | ||
condition = new SqlString(string.IsNullOrEmpty(on) && (ForceFilter || enabledForManyToOne.Count > 0) | ||
? join.Joinable.FilterFragment(join.Alias, enabledForManyToOne) | ||
: on); | ||
if (string.IsNullOrEmpty(on)) | ||
{ | ||
var enabledFiltersForJoin = ForceFilter ? enabledFilters : FilterHelper.GetEnabledForManyToOne(enabledFilters); | ||
condition = new SqlString(ForceFilter || enabledFiltersForJoin.Count > 0 | ||
Comment on lines
+200
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have considered
But if instead we consider the many-to-one filter setting should be taken into account for arbitrary joins, meaning the filters should be disabled on arbitrary joins if that setting is disabled, then we should instead just add a breaking change in the releases note for v5.3.0. |
||
? join.Joinable.FilterFragment(join.Alias, enabledFiltersForJoin) | ||
: on); | ||
} | ||
else | ||
{ | ||
condition = new SqlString(on); | ||
} | ||
} | ||
|
||
if (withClauseFragment != null) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially though the
GetOnCondition
implementation may be troublesome in some cases, because it does filterenabledFilters
according to theiruse-many-to-one
setting:nhibernate-core/src/NHibernate/Type/EntityType.cs
Lines 501 to 512 in e99cf43
And later here, we take the
on
clause if it is not empty, instead of computing it with all filters ifForceFilter
. It appears thison
clause will always be empty in our case, arbitrary joins, becauseGetOnCondition
current implementation always yields that excepted for property-ref associations.nhibernate-core/src/NHibernate/Type/EntityType.cs
Lines 496 to 499 in e99cf43
So, the current change is enough to fix the trouble. I cannot think of a related test case demonstrating a need to change
GetOnCondition
. This implementation looks a bit brittle to me, but a patch change is not the place to get things better from that viewpoint, unless we can demonstrate a failing case.