-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Rewhere on a has_many association drops WHERE clause in 4.2.4 #21955
Comments
It looks like |
jbranchaud
added a commit
to jbranchaud/rails
that referenced
this issue
Oct 19, 2015
With `unscope!` called last, it undoes `where` constraints of the same value when the `where` is chained after the `unscope`. This is what a `rewhere` does. This is undesirable behavior. The included tests demonstrate both the `unscope(...).where(...)` behavior as well as the direct use of `rewhere(...)`. This is in reference to rails#21955.
rafaelfranca
added a commit
that referenced
this issue
Oct 20, 2015
rafaelfranca
added a commit
that referenced
this issue
Oct 20, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In 4.2.4, it appears that using a
rewhere
scope on ahas_many
relation is broken (or at least, has materially changed from earlier versions).The following gists demonstrate the issue:
activerecord 4.2.3 ('working' example)
https://gist.github.com/scottohara/08d73351e27adeb6f694
In this example, a
rewhere
scope on thehas_many :comments
association arbitrarily overrides theWHERE
clause to a different id (ie.-> { rewhere(post_id: 99) }
).The SQL
SELECT
statement forpost.comments
is as expected:activerecord 4.2.4 ('broken' example)
https://gist.github.com/scottohara/70a07172882e067aaa96
This is identical to the above gist, but with the activerecord gem version bumped to 4.2.4.
The presence of the
rewhere
scope now causes the SQLSELECT
statement to lose itsWHERE
clause entirely; yielding:The same behaviour (as 4.2.4) is present in edge (master).
Is this a regression in 4.2.4, or an expected behaviour change? (and if expected, what would be the correct way to use
rewhere
in 4.2.4?)The text was updated successfully, but these errors were encountered: