-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Add Lucky::Params#get_all #1389
Add Lucky::Params#get_all #1389
Conversation
end | ||
|
||
private def get_all_params(params, key : String) | ||
vals = params.fetch_all(key + "[]") |
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.
You might ask, "What about if the user doesn't want to use the key[]
pattern?"
I'm open to feedback but I think we're pretty clear in Lucky that we prefer convention with a backdoor and the backdoor in this scenario is to access the params directly: params.from_query.fetch_all("keys")
vals = params.fetch_all(key + "[]") | ||
if vals.any? | ||
vals | ||
else | ||
nil | ||
end |
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.
What do you think about this?
vals = params.fetch_all(key + "[]") | |
if vals.any? | |
vals | |
else | |
nil | |
end | |
params.fetch_all(key + "[]").try &.any? |
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.
Doesn't #any?
return a boolean? #fetch_all
always returns an array, the goal is to return nil if the array is empty
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.
For the most part, this looks good. I just have the one concern as far as the API for it goes. Also just to be clear that the intended use is different from the params.many_nested
method, right? This is just for supporting raw arrays in params?
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.
Sweet! Yeah, this feels pretty good. Thanks for making the change 😃
Purpose
Fixes #1380
Related luckyframework/avram#408
Description
Allows fetching an array of values from
Lucky::Params
. This is needed to support things like multi-select inputs, and array columns inAvram::Model
.Checklist
crystal tool format spec src
./script/setup
./script/test