Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of projection dsl is not available in Relation#exclude #412

Open
wuarmin opened this issue Sep 19, 2022 · 0 comments
Open

Use of projection dsl is not available in Relation#exclude #412

wuarmin opened this issue Sep 19, 2022 · 0 comments

Comments

@wuarmin
Copy link

wuarmin commented Sep 19, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant