Module: TemporalTables::AssociationExtensions

Defined in:
lib/temporal_tables/association_extensions.rb

Overview

Uses the time from the “at” field stored in the record to filter queries made to associations.

Instance Method Summary collapse

Instance Method Details

#skip_statement_cache?(scope) ⇒ Boolean

There seems to be an issue with the statement cache for history associations. This may be due to the at_value not being part of how the relations are hashed, or that the cached statements are not parameterized. Will require further investigation. In the meantime, we can workaround this issue by disabling the statement cache for History queries.

Returns:

  • (Boolean)


28
29
30
# File 'lib/temporal_tables/association_extensions.rb', line 28

def skip_statement_cache?(scope)
  klass.is_a?(TemporalTables::TemporalClass::ClassMethods) || super(scope)
end

#target_scopeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/temporal_tables/association_extensions.rb', line 7

def target_scope
  # Kludge: Check +public_methods+ instead of using +responds_to?+ to
  # bypass +delegate_missing_to+ calls, as in +ActiveStorage::Attachment+.
  # Using responds_to? results in an infinite loop stack overflow.
  if @owner.public_methods.include?(:at_value)
    # If this is a history record but no at time was given,
    # assume the record's effective to date minus 1 microsecond
    # The logic here is to provide the association's history record at the end of
    # the parent record's effective period. Since effective ranges are exclusive of
    # the eff_to value, and the eff_* columns are datetime types with a precision of microseconds,
    # 1 microsecond before eff_to is the end of the inclusive boundary to accomplish this.
    super.at(@owner.at_value || (@owner.eff_to - TemporalTables::ONE_MICROSECOND))
  else
    super
  end
end