Relation's dataset doesn't apply when the relation is used in a join
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with the UserRepo#with_undone_tasks entry point and the relation definitions for UndoneTasks and Users. Trace how join(undone_tasks) and combine(:undone_tasks) build the SQL query, checking where the undone_tasks dataset filters and ordering are lost. Done means the generated join includes the dataset conditions and ordering while loading the combined undone tasks.
Written by the indexing model from the issue text.
Description
Hi! Here I make use of relation dataset to model different types of a task. In UserRepo I want a fetch all users having undone tasks and I want to load them with their undone tasks. The issue is that join with undone_tasks relation doesn't build a SQL query with the filters from undone_tasks dataset.
class Users < ROM::Relation[:sql]
schema(infer: true) do
associations do
has_many :done_tasks
has_many :undone_tasks
has_many :tasks
end
end
end
class Tasks < ROM::Relation[:sql]
schema(:tasks, infer: true) do
associations { belongs_to :user }
end
end
class UndoneTasks < ROM::Relation[:sql]
schema(:tasks, infer: true) do
associations { belongs_to :user }
end
dataset { where(done: false).order(:created_at).qualify }
end
class DoneTasks < ROM::Relation[:sql]
schema(infer: true) do
associations { belongs_to :user }
end
dataset { where(done: true).order(:created_at).qualify }
end
class UserRepo < ROM::Repository::Root[:users]
def with_undone_tasks
users
.join(undone_tasks)
.combine(:undone_tasks)
.to_a
end
end
- Dominant language
- Ruby
- Stars
- 220
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rom-rb/rom-sql
-
bug help wanted
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
bug help wanted
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
bug help wanted
Difficulty 3/5 1-2 days Newbie friendliness 42/100
-
bug help wanted
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
bug help wanted
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
バグ
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
voxpupuli/puppet-epel#186 · 1 comment ·
-
external_created_at is no longer used for the message timestamp since the new message UI (v4.4.0) OpenBug Frontend
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
TheOdinProject/curriculum#31402 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100