Skip to content

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

Description

@wuarmin

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions