Class: ClickhouseRuby::ActiveRecord::RelationExtensions::PrewhereChain

Inherits:
Object
  • Object
show all
Defined in:
lib/clickhouse_ruby/active_record/relation_extensions.rb

Overview

Chain object for prewhere.not syntax

Allows negation of prewhere conditions:

Model.prewhere.not(deleted: true)
# PREWHERE NOT(deleted = 1)

Instance Method Summary collapse

Constructor Details

#initialize(relation) ⇒ PrewhereChain

Returns a new instance of PrewhereChain.



359
360
361
# File 'lib/clickhouse_ruby/active_record/relation_extensions.rb', line 359

def initialize(relation)
  @relation = relation
end

Instance Method Details

#not(opts, *rest) ⇒ ActiveRecord::Relation

Negate the prewhere conditions

Parameters:

  • opts (Hash, String, Arel::Nodes::Node)

    the conditions to negate

  • rest (Array)

    bind parameters

Returns:

  • (ActiveRecord::Relation)

    the relation with negated prewhere



368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/clickhouse_ruby/active_record/relation_extensions.rb', line 368

def not(opts, *rest)
  condition_to_negate = case opts
                        when Hash
                          build_combined_condition(opts)
                        when String
                          Arel.sql(@relation.sanitize_sql_array([opts, *rest]))
                        else
                          opts
                        end

  negated = Arel::Nodes::Not.new(condition_to_negate)
  @relation.prewhere!(negated)
end