-
Notifications
You must be signed in to change notification settings - Fork 22k
Allow relations with different SQL comments in the or
method
#38172
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
How do you think |
Sorry, I haven't used Post.optimizer_hints("MAX_EXECUTION_TIME(50000)").or(
Post.optimizer_hints("MAX_EXECUTION_TIME(20000)"))
#=> ? |
I found the following description in the MySQL documentation.
The query when the condition conflicts is valid (although there is a warning), so I think that it is no problem to simply combine the values. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
ff9ed3d
to
53df5e1
Compare
I don't come up with a use case for using |
To work
|
Sure, that's enough. |
81511b8
to
c4e30fc
Compare
# they must differ only by #where (if no #group has been defined) or #having (if a #group is | ||
# present). Neither relation may have a #limit, #offset, or #distinct set. | ||
# they must differ only by #where (if no #group has been defined), #having (if a #group is | ||
# present), #annotate or #optimizer_hints. Neither relation may have a #limit, #offset, or #distinct set. |
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'm not excited to talk about the annotate
and the optimizer_hints
in the same breath with the where
and the having
.
We had hit the structually incompatible error on several occasions in the past (#29461, ea61391), in that time, we just relaxed the limitation to address the error, but didn't mention about what values are allowed/ignored.
I agree that there is room for improvement in the doc, but how about discussing it in another PR about how to improve it?
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.
Thank you for telling me related pull requests.
I understood.
I reverted the changes in doc and force-pushed.
@@ -139,6 +139,14 @@ def test_or_with_scope_on_association | |||
end | |||
end | |||
|
|||
def test_or_with_annotate | |||
quoted_posts = Post.quoted_table_name |
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.
The quoted_table_name
should be escaped by Regexp.escape
, since it is qouted as [posts]
in SQLServer.
quoted_posts = Post.quoted_table_name | |
quoted_posts = Regexp.escape(Post.quoted_table_name) |
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.
Thanks for your review. I updated.
An error occurs when you pass a relation with SQL comments to the `or` method. ```ruby class Post scope :active, -> { where(active: true).annotate("active posts") } end Post.where("created_at > ?", Time.current.beginning_of_month) .or(Post.active) ``` In order to work without `ArgumentError`, it changes the `or` method to ignore SQL comments in the argument. Ref: rails#38145 (comment)
Thanks! |
Allow relations with different SQL comments in the `or` method
An error occurs when you pass a relation with SQL comments to the
or
method.In order to work without
ArgumentError
, it changes theor
method to ignore SQL comments in the argument.Ref: #38145 (comment)