Module: ChronoModel::Patches::Batches
- Defined in:
- lib/chrono_model/patches/batches.rb
Overview
Overrides the default batch methods for historical models
In the default implementation, cursor defaults to primary_key, which is 'id'.
However, historical models need to use 'hid' instead of 'id'.
This patch addresses an issue where with_hid_pkey is called after the cursor
is already set, potentially leading to incorrect behavior.
Notes:
find_eachandfind_in_batchesinternally utilizein_batches. However, in the upcoming Rails 8.0, this implementation will be insufficient due to a new conditional branch usingenum_for.- This approach prevents specifying 'id' as a cursor for historical models. If 'id' is needed, it must be handled separately.
See: ifad/chronomodel#321 for more context
Instance Method Summary collapse
Instance Method Details
#find_each(**options) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/chrono_model/patches/batches.rb', line 22 def find_each(**) return super unless try(:history?) [:cursor] = 'hid' if [:cursor] == 'id' with_hid_pkey { super } end |
#find_in_batches(**options) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/chrono_model/patches/batches.rb', line 30 def find_in_batches(**) return super unless try(:history?) [:cursor] = 'hid' if [:cursor] == 'id' with_hid_pkey { super } end |
#in_batches(**options) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/chrono_model/patches/batches.rb', line 38 def in_batches(**) return super unless try(:history?) [:cursor] = 'hid' if [:cursor] == 'id' with_hid_pkey { super } end |