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
Adding the ability to join with OR from a where clause #1103
Conversation
I will also be creating a PR for master once all the kinks are worked out on this one. |
If you set the default join with to be ' OR ' would that accidentally give you a bigger scope than you intended? Consider you have a |
pairs_to_clauses(field_pairs).join(join_with) | ||
def construct_query(field_pairs, join_with = default_join_with) | ||
clauses = pairs_to_clauses(field_pairs) | ||
return clauses.join("") if clauses.count <= 1 |
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.
would clauses.first
be more efficient? Then we don't have to allocate a new string.
@jcoyne The default join_with is still AND. We are only using OR when the user passes it with a join_with option. |
@jcoyne I changed the default to ' OR ' and there are a bunch of test failures. I think leaving the default as 'AND' in 9.7 is the right move. We could consider changing the default in master. To answer your question above you would still get an AND in between for example here is an error from the errors I got when I changed it to OR
|
@Cam156 right, but that looks like a bad expectation to me. I'd like to see the use case that emerged from. |
@jcoyne I agree the OR makes more sense, but I am trying to make the smallest change here in the 9.7.x branch so we can reasonably stay in the 9.7.x numbering. I can test changing to OR as the default with the sufia test, but I'm worried it will have unforeseen consequences in a patch release. |
The current expected behavior is AND. I think we should preserve the expected behavior. With this PR, you now have the option of using OR so I think this PR solves the problem as described. |
To me it is clear that our existing API is not behaving correctly, and we should fix it. It is a bug (even if it causes some test failures). We should not introduce a new API which we must support in perpetuity to do exactly how it should have worked in the first place. |
When I added this test https://github.com/psu-stewardship/active_fedora/commit/d0397ab800d90e119a9647e8f47b1f19f3b76ff1#diff-d6939355441580118b5afdbbd0a98049R44 , which will fail if we make my suggested change, it was not because I was being intentional about supporting that feature, it was more of just testing the existing behavior. |
@jcoyne 👌 If this is a bug fix then I am good with it. I will make the change. We can always bug fix again. So you would like to drop the optional join_with and just change the where clause to use OR? |
This allows for finding all the objects that are 'this OR that' whihc is how the acrive record where with an array works. Added parens around cluases since 'abc' AND 'ddd' OR 'fff' is not the same as 'abc' AND ('ddd' OR 'fff'). This was not an issue before since all the clauses were joined with AND
@jcoyne Better? |
This allows for finding all the objects that are 'this OR that' instead of just 'this AND that'
Added parens around cluases since 'abc' AND 'ddd' OR 'fff' is not the same as 'abc' AND ('ddd' OR 'fff'). This was not an issue before since all the clauses were joined with AND