-
Notifications
You must be signed in to change notification settings - Fork 144
[Api::Filter] Allow filtering '=' via arrays #1061
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
Conversation
Inverts the "if" statement to remove the use of `target`, which is confusing to read. Instead the "expr" is built first, and then based on the `:logical_or` value, is put in the proper array. This makes it just a bit easier to logically parse as a human, but is functionally the same.
Makes the collections for `and_expressions` and `or_expressions` `attribute_readers`, so they are available outside of the `parse` method (for a future refactoring).
Makes `.composite_expression` it's own method. Does a few things: - Decreases the size of `.parse`, which is quite large already - Allows future refactoring and enhancement of that method in a more readable fashion
|
Please review and let us know what you think. This is to help Melody with a form conversion, and doing this avoids having to bring everything back and filter in Ruby, but also avoids needing to touch |
4011e64 to
080bc01
Compare
kbrock
left a comment
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.
This looks very nice Nick.
I'm amused that I want to get rid of a double use variable and introduce a single use one. Those do not have a strong reaction from me.
Really don't like the introduction of the two global variables.
We can discuss if you want, but not a hill I'd die on.
| {:logical_or => logical_or, :operator => method, :attr => filter_attr, :value => filter_value} | ||
| end | ||
|
|
||
| def composite_expression |
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.
not a big fan. I liked parse only having local variables.
can you extract this logic while keeping the variables out of the global scope?
composite_expression(and_expressions, or_expressions)
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.
Humbly disagree and don't plan to change. This is pretty idiomatic Ruby to use instance variables (not "global") like this and I think it makes definitions and callers less verbose and wordy.
For example, I picked puma as an example, and the first class I looked at does something pretty much like this with the first method I found:
https://github.com/puma/puma/blob/master/lib/puma/client.rb#L96-L98
In this case, the @ready var is called directly instead of using an attr_reader, but I think the general idea is the same.
So unless I get push back from others, I don't plan to change.
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.
lol. you've made changes like this before. it is your style.
the or expressions and and expressions is only valid within the context of parse
I also am not that fond of how the parsing is being performed, so elevating the local variables to globals further sets it in stone.
Can you be bribed to pass those 2 variables into the local private method composite_expression and do away with these global class variables?
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.
globalclass variables
Instance variables... they are instance variables...
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.
ugh. ^ what he said
and LGTM. lets merge this PR
Adds functionality to the API to allow filtering a particular column by
one of many types of values. This could be particularly useful when
filtering via a `type` column that is an STI column.
The SQL that would be generated from the filter would be the following:
SELECT *
FROM miq_requests
WHERE (type = "MiqProvisionRequest" OR type = "VmMigrateRequest")
This avoids having to make changes to `MiqExpression` that would allow
for something similar to how `where(:type => [a,b,c])` works already,
and also ensures that we are using something that can be converted into
SQL on the backend.
080bc01 to
e607423
Compare
|
Checked commits NickLaMuro/manageiq-api@4dbe1c9~...e607423 with ruby 2.6.3, rubocop 1.13.0, haml-lint 0.35.0, and yamllint |
|
Backported to |
[Api::Filter] Allow filtering '=' via arrays (cherry picked from commit b6e5172)
Adds functionality to the API to allow filtering a particular column by one of many types of values. This could be particularly useful when filtering via a
typecolumn that is an STI column.The SQL (functionally) that would be generated from the filter would be the following:
This avoids having to make changes to
MiqExpressionthat would allow for something similar to howwhere(:type => [a,b,c])works already, and also ensures that we are using something that can be converted into SQL on the backend.Links
QA
I tested this using the following script:
And confirmed in the log that I was getting a proper query in the database using these filters: