You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a relation that corresponds to a table with a different name than the table, then joining will fail because the JOIN query will try to join to a table with the relation name, not the table name. I'm fairly sure this only happens when you pass a block to the join method to set the join conditions.
To Reproduce
The following snippet will exhibit this bug:
require "rom"
rom = ROM.container(:sql, 'sqlite::memory') do |conf|
conf.default.create_table(:users) do
primary_key :id
column :name, String, null: false
end
conf.default.create_table(:my_tasks) do
primary_key :id
column :name, String, null: false
foreign_key :user_id, :users, null: false
end
conf.relation(:users) do
schema(infer: true)
end
conf.relation(:tasks) do
schema(:my_tasks, infer: true) do
associations do
belongs_to(:user)
end
end
end
end
rom.relations[:users].join(rom.relations[:tasks]) do |users:, tasks:|
tasks[:user_id].is(users[:id])
end.to_a
If you inspect the query before calling to_a you will see the following:
SELECT `users`.`id`, `users`.`name` FROM `users` INNER JOIN `tasks` ON (`my_tasks`.`user_id` = `users`.`id`) ORDER BY `users`.`id`
As you can see, the query is trying to join a table named tasks and not my_tasks as you might expect.
Expected behavior
The JOIN should reference the correct table name when supplying a block with join conditions.
relation#join block dsl should use dataset name not alias
[changelog]
version: "unreleased"
date:
fixed: "`Relation#join` no longer crashes when aliased relation is used with a block (issue #369) (@abrthel)"
Describe the bug
If you have a relation that corresponds to a table with a different name than the table, then joining will fail because the JOIN query will try to join to a table with the relation name, not the table name. I'm fairly sure this only happens when you pass a block to the join method to set the join conditions.
To Reproduce
The following snippet will exhibit this bug:
If you inspect the query before calling
to_a
you will see the following:As you can see, the query is trying to join a table named
tasks
and notmy_tasks
as you might expect.Expected behavior
The JOIN should reference the correct table name when supplying a block with join conditions.
Your environment
The text was updated successfully, but these errors were encountered: