Skip to content

Commit

Permalink
Change Relation#load to match AR implementation
Browse files Browse the repository at this point in the history
`Relation#load` method:
- Accepts a block as an argument
- Checks also for `scheduled?` predicate
- Returns the `Relation` itself (not an array)

This signature is available from 7.0.0, the minimum requested AR version

Close #297

Ref: rails/rails@caa178c
  • Loading branch information
tagliala committed Jun 2, 2024
1 parent 0addc9c commit 8015a41
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/chrono_model/patches/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
super

super.each { |record| record.as_of_time!(@_as_of_time) }
@records.each { |record| record.as_of_time!(@_as_of_time) } if @_as_of_time

self
end

def merge(*)
Expand Down

0 comments on commit 8015a41

Please sign in to comment.