Raising an error when query methods have blank arguments.#9258
Conversation
|
I would disagree. Often times you want this 'null pattern' behaviour when generating parameters dynamically and this change would force you to write unnecessary conditional statements. |
|
@tadast Could you show some code that's affected, before & after? Note that we're checking that any arguments are passed, not the argument isn't null or an empty string. >> [''].blank?
=> false |
|
Seems good. Could you add a changelog entry? |
|
@tadast 👍 |
…k arguments are meaningless.
|
Changelog entry has been added. |
Raising an error when query methods have blank arguments.
|
Sorry, I don't want to cause any more trouble, but I'm thinking about it again... What if someone has a method like this: def fancy_filter(options = {})
related = []
query = {}
if options[:author_name]
query[:author] = { name: options[:author_name] }
related << :author
end
where(query).references(related)
endwould it not break things? In cases like this people would have to make sure to omit the |
|
So where is handled separately. I only changed the functionality where blank arguments make strictly no sense. Where still returns self. |
|
Again: >> [[]].blank?
=> falseIt'll only break if you do |
|
🙊 |
|
I'm confused too; sorry! Given the discussion above, the The Are there tests for this I can read? |
|
Sorry, the CHANGELOG is misleading and there is an error in it. I'm sending in a PR to fix this and add some more documentation and tests #9332. |
Currently, whenever an activerecord query is included with a nil or nil-like object, no argument error is given. For instance:
Posts.limit().all = Posts.all
That relation is completely useless when there are blank-like arguments. For methods which this doesn't make sense for, I'm adding checks which will raise an ArgumentError.