Skip to content

Commit

Permalink
references(:developers_projects_join) isn't needed if using where
Browse files Browse the repository at this point in the history
… with hash condition
  • Loading branch information
kamipo committed Jun 25, 2018
1 parent 5eed3bb commit 8324791
Showing 1 changed file with 2 additions and 16 deletions.
Expand Up @@ -697,24 +697,13 @@ def test_habtm_respects_select_query_method
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}"
Expand All @@ -723,10 +712,7 @@ def test_join_with_group

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

Expand Down

0 comments on commit 8324791

Please sign in to comment.