Hey,
I have following use-case:
I want to create a UserMentions
-relation, which is derived from a mentions-table by using group by. It should only provide one entry per issue, user and read flag.
class UserMentions < ROM::Relation[:sql]
dataset {
select { [issue_id, user_id, read, max(:created).as(:created)] }
.group(:issue_id, :user_id, :read)
}
schema(:mentions, infer: true, as: :user_mentions) do
associations do
belongs_to :issue
belongs_to :user
end
end
end
Querying from UserMentions
works as expected, but if I want to join UserMentions
, i.e.
issues.join(:user_mentions)
the resulting SQL looks like this:
INNER JOIN "mentions" ON ("issues"."id" = "mentions"."issue_id")
instead of
INNER JOIN (
SELECT "issue_id", "user_id", "read", max("created") AS "created"
FROM "mentions"
GROUP BY "issue_id", "user_id", "read"
) as "mentions" ON ("issues"."id" = "mentions"."issue_id")
Do you have a hint, how I could solve my issue with ROM?
Thanks!