Class: ChronoModel::Patches::JoinNode

Inherits:
Arel::Nodes::SqlLiteral
  • Object
show all
Defined in:
lib/chrono_model/patches/join_node.rb

Overview

This class supports the AR 5.0 code that expects to receive an Arel::Table as the left join node. We need to replace the node with a virtual table that fetches from the history at a given point in time, we replace the join node with a SqlLiteral node that does not respond to the methods that AR expects.

This class provides AR with an object implementing the methods it expects, yet producing SQL that fetches from history tables as-of-time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(join_node, history_model, as_of_time) ⇒ JoinNode

Returns a new instance of JoinNode.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chrono_model/patches/join_node.rb', line 18

def initialize(join_node, history_model, as_of_time)
  @name        = join_node.table_name
  @table_name  = join_node.table_name
  @table_alias = join_node.table_alias

  @as_of_time  = as_of_time

  virtual_table = history_model
                  .virtual_table_at(@as_of_time, table_name: @table_alias || @table_name)

  super(virtual_table)
end

Instance Attribute Details

#as_of_timeObject (readonly)

Returns the value of attribute as_of_time.



16
17
18
# File 'lib/chrono_model/patches/join_node.rb', line 16

def as_of_time
  @as_of_time
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/chrono_model/patches/join_node.rb', line 16

def name
  @name
end

#table_aliasObject (readonly)

Returns the value of attribute table_alias.



16
17
18
# File 'lib/chrono_model/patches/join_node.rb', line 16

def table_alias
  @table_alias
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



16
17
18
# File 'lib/chrono_model/patches/join_node.rb', line 16

def table_name
  @table_name
end