1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

references(:developers_projects_join) isn't needed if using where with hash condition

This commit is contained in:
Ryuta Kamizono 2018-06-26 04:44:09 +09:00
parent 5eed3bba5e
commit 83247916c9

View file

@ -697,24 +697,13 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
end
def test_join_table_alias
# FIXME: `references` has no impact on the aliases generated for the join
# query. The fact that we pass `:developers_projects_join` to `references`
# and that the SQL string contains `developers_projects_join` is merely a
# coincidence.
assert_equal(
3,
Developer.references(:developers_projects_join).merge(
includes: { projects: :developers },
where: "projects_developers_projects_join.joined_on IS NOT NULL"
).to_a.size
Developer.includes(projects: :developers).where.not("projects_developers_projects_join.joined_on": nil).to_a.size
)
end
def test_join_with_group
# FIXME: `references` has no impact on the aliases generated for the join
# query. The fact that we pass `:developers_projects_join` to `references`
# and that the SQL string contains `developers_projects_join` is merely a
# coincidence.
group = Developer.columns.inject([]) do |g, c|
g << "developers.#{c.name}"
g << "developers_projects_2.#{c.name}"
@ -723,10 +712,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal(
3,
Developer.references(:developers_projects_join).merge(
includes: { projects: :developers }, where: "projects_developers_projects_join.joined_on IS NOT NULL",
group: group.join(",")
).to_a.size
Developer.includes(projects: :developers).where.not("projects_developers_projects_join.joined_on": nil).group(group.join(",")).to_a.size
)
end