diff --git a/lib/chrono_model/patches/relation.rb b/lib/chrono_model/patches/relation.rb index 56eee6f..8a7a195 100644 --- a/lib/chrono_model/patches/relation.rb +++ b/lib/chrono_model/patches/relation.rb @@ -23,10 +23,12 @@ def empty_scope? @values == klass.unscoped.as_of(as_of_time).values end - def load - return super unless @_as_of_time && !loaded? + def load(&block) + return super unless @_as_of_time && (!loaded? || scheduled?) super.each { |record| record.as_of_time!(@_as_of_time) } + + self end def merge(*) diff --git a/spec/chrono_model/time_machine/as_of_spec.rb b/spec/chrono_model/time_machine/as_of_spec.rb index 0d00099..acae03b 100644 --- a/spec/chrono_model/time_machine/as_of_spec.rb +++ b/spec/chrono_model/time_machine/as_of_spec.rb @@ -181,5 +181,11 @@ it { expect($t.baz.as_of($t.bar.ts[2]).bar.foo.name).to eq 'new foo' } it { expect($t.baz.as_of($t.bar.ts[3]).bar.foo.name).to eq 'new foo' } end + + describe '#load' do + it 'returns a relation' do + expect(Foo.as_of(Time.now).load).to be_an(ActiveRecord::Relation) + end + end end end