Class: ActiveRecord::QueryMethods::WithChain

Inherits:
Object
  • Object
show all
Defined in:
lib/postgres_with/active_record/relation/query_methods.rb

Overview

WithChain objects act as placeholder for queries in which #with does not have any parameter. In this case, #with must be chained with #recursive to return a new relation.

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ WithChain

Returns a new instance of WithChain.



6
7
8
# File 'lib/postgres_with/active_record/relation/query_methods.rb', line 6

def initialize(scope)
  @scope = scope
end

Instance Method Details

#materialized(*args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/postgres_with/active_record/relation/query_methods.rb', line 10

def materialized(*args)
  materialized_args = args.flat_map do |arg|
    case arg
    when Hash
      name = arg.keys.first
      new_name = "_materialized_#{name}"
      { new_name => arg[name] }
    else
      arg
    end
  end
  @scope.with_values += materialized_args
  @scope
end

#recursive(*args) ⇒ Object

Returns a new relation expressing WITH RECURSIVE



26
27
28
29
30
# File 'lib/postgres_with/active_record/relation/query_methods.rb', line 26

def recursive(*args)
  @scope.with_values += args
  @scope.recursive_value = true
  @scope
end