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
Collapse where constraints to the Arel::Nodes::And node #12011
Collapse where constraints to the Arel::Nodes::And node #12011
Conversation
/cc @tenderlove, @senny, @rafaelfranca |
Build should be restarted because of minitest problems. |
@pftg done. |
Thanks @senny |
@senny, also may you fast review this. Travis failed because of |
Rebased and tests are passed. |
@@ -41,6 +41,15 @@ def test_join_conditions_added_to_join_clause | |||
assert_no_match(/WHERE/i, sql) | |||
end | |||
|
|||
def test_join_association_conditions_added_to_join_clause | |||
sql = Author.joins(:welcome_posts_with_comment).to_sql | |||
assert_match(/AND \(comments_count = 1\)/i, sql) |
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.
Can we assert the result instead of the SQL? The SQL generation can change in the future and this test will broke.
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 gist has very good test cases. Mind to reuse they? https://gist.github.com/iwiznia/6295952
In order to remove duplication with joining arel where constraints with `AND`, all constraints on `build_arel` are collapsed into one head node: `Arel::Nodes::And` Closes: rails#11963
@rafaelfranca thanks for feedback, I updated Changelog, and replaced sql assertions similar to gists examples by asserting results. |
…ation_scope Collapse where constraints to the Arel::Nodes::And node Conflicts: activerecord/CHANGELOG.md
…ation_scope Collapse where constraints to the Arel::Nodes::And node Conflicts: activerecord/CHANGELOG.md Conflicts: activerecord/CHANGELOG.md
In order to remove duplication with joining where constraints by
AND
on traversearel.constraints
,refactored
collapse_wheres
to add toarel.wheres
onbuild_arel
only one nodeArel::Nodes::And
.This refactoring remove duplication to which fixed #11963:
because
Arel::Nodes::Node#and
expected that argument (in our caserel.arel.constraints
) is notArray
, in that wayArel::Visitors::ToSql
on visitingArray
returns,
instead ofAND
.