Skip to content

Commit 21420ef

Browse files
authored
Merge pull request #151 from osyo-manga/add-support_rails7_1
Add support Rails 7.1
2 parents 7e4b37f + 2875d7c commit 21420ef

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ workflows:
3232
gemfile:
3333
- rails_6.1
3434
- rails_7.0
35+
- rails_7.1
3536
- rails_main
3637
exclude:
3738
- ruby-version: '3.2'

Appraisals

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ end
1111
appraise "rails-7.0" do
1212
gem "rails", "~> 7.0.1"
1313
end
14+
15+
appraise "rails-7.1" do
16+
gem "rails", "~> 7.1.0"
17+
end

gemfiles/rails_7.1.gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "appraisal"
6+
gem "rails", "~> 7.1.0"
7+
8+
gemspec path: "../"

lib/activerecord-bitemporal/bitemporal.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,18 @@ def destroy(force_delete: false, operated_at: Time.current)
383383
false
384384
end
385385

386+
if Gem::Version.new("7.1.0") <= ActiveRecord.version
387+
# MEMO: Since Rails 7.1 #_find_record refers to a record with find_by!(@primary_key => id)
388+
# But if @primary_key is "id", it can't refer to the intended record, so we hack it to refer to the record based on self.class.bitemporal_id_key
389+
# see: https://github.com/rails/rails/blob/v7.1.0/activerecord/lib/active_record/persistence.rb#L1152-#L1171
390+
def _find_record(*)
391+
tmp_primary_key, @primary_key = @primary_key, self.class.bitemporal_id_key
392+
super
393+
ensure
394+
@primary_key = tmp_primary_key
395+
end
396+
end
397+
386398
module ::ActiveRecord::Persistence
387399
# MEMO: Must be override ActiveRecord::Persistence#reload
388400
alias_method :active_record_bitemporal_original_reload, :reload unless method_defined? :active_record_bitemporal_original_reload

0 commit comments

Comments
 (0)