Use of projection dsl is not available in Relation#exclude
wuarmin opened this issue · comments
Armin commented
Describe the bug
It I try to use the projection dsl in combination with #exlude...
mentions
.select { integer::count(issue_id).as(:unit_mention_count) }
.where(unit_id: 3, read: false)
.exclude { user_ids.any(1) }
...I get the following error:
NoMethodError:
undefined method `any' for #<Sequel::SQL::Identifier @value=>:user_ids>
.exclude { user_ids.any(1) }
Expected behavior
SELECT COUNT(\"mentions\".\"issue_id\") AS \"unit_mention_count\" FROM \"mentions\" WHERE ((\"unit_id\" = 3) AND (\"read\" IS FALSE) AND NOT (1 = ANY(\"mentions\".\"user_ids\")))
Workaround
Overwrite #exclude at relation
class Mentions < ROM::Relation[:sql]
schema(:mentions, infer: true) do
end
def exclude(*args, &block)
if block
exclude(*args).exclude(schema.canonical.restriction(&block))
elsif args.size == 1 && args[0].is_a?(Hash)
new(dataset.exclude(coerce_conditions(args[0])))
elsif !args.empty?
new(dataset.exclude(*args))
else
self
end
end
end
WDYT? I could provide a PR.