-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading associated temporal records only ever works once #25
Comments
I've run into a likely related issue. There's something weird going on with the activerecord statement cache where it can't tell the difference between history queries of the same model. I haven't had a chance to dig in deep yet, but my solution so far has been a monkeypatch to disable it for History records module TemporalPatch
class << self
def apply_patch
puts 'asdfasdf'
const = find_const
mtd = find_method(const)
# make sure the class we want to patch exists;
# make sure the #filter method exists and accepts exactly one argument
unless const && mtd&.arity == 1
raise 'Could not find class or method when patching ' \
"ActiveRecord::Associations:Association's skip_statement_cache method. Please investigate."
end
const.prepend(InstanceMethods)
end
private
def find_const
Kernel.const_get('ActiveRecord::Associations::Association')
rescue NameError
# return nil if the constant doesn't exist
end
def find_method(const)
return unless const
const.instance_method(:skip_statement_cache?)
rescue NameError
# return nil if the constant doesn't exist
end
end
module InstanceMethods
private
def skip_statement_cache?(scope)
klass.name.end_with?('History') ||
reflection.has_scope? ||
scope.eager_loading? ||
klass.scope_attributes? ||
reflection.source_reflection.active_record.default_scopes.any?
end
end
end
TemporalPatch.apply_patch
|
Definitely related. Your patch makes my tests green. I'll go with this for now: def skip_statement_cache?(scope)
klass.is_a?(TemporalTables::TemporalClass::ClassMethods) || super(scope)
end |
monkey-patch implemented in v3.0.0 |
... per table, I guess.
In a one-to-many association of two temporal tables, loading the parent (history) record of the child (history) record works exactly once (per runtime) for me, and never again.
Example:
Expectation:
Each call of
post_of_comment
should find aPostHistory
.Current behavior:
The first attempt succeeds, all other attempts return
nil
.This reproduction case is on Github at Zyndoras/temporal_tables_demo (see
lib/tasks/demo.rake
)It seems to me that the timestamp used to load the PostHistory is somewhat arbitrary and does not necessarily match anything related to the records created or the timestamp passed to
history.at
.What I do not understand though, is why it consistently works the first time the function is called, but then never again.
The text was updated successfully, but these errors were encountered: