Skip to content

Commit

Permalink
Add support Rails 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
osyo-manga committed Jan 12, 2024
1 parent 7e4b37f commit 0bd3a34
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ end
appraise "rails-7.0" do
gem "rails", "~> 7.0.1"
end

appraise "rails-7.1" do
gem "rails", "~> 7.1.0"
end
8 changes: 8 additions & 0 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "rails", "~> 7.1.0"

gemspec path: "../"
12 changes: 12 additions & 0 deletions lib/activerecord-bitemporal/bitemporal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,18 @@ def destroy(force_delete: false, operated_at: Time.current)
false
end

if Gem::Version.new("7.1.0") <= ActiveRecord.version
# MEMO: Since Rails 7.1 #_find_record refers to a record with find_by!(@primary_key => id)
# 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
# see: https://github.com/rails/rails/blob/v7.1.0/activerecord/lib/active_record/persistence.rb#L1152-#L1171
def _find_record(*)
tmp_primary_key, @primary_key = @primary_key, self.class.bitemporal_id_key
super
ensure
@primary_key = tmp_primary_key
end
end

module ::ActiveRecord::Persistence
# MEMO: Must be override ActiveRecord::Persistence#reload
alias_method :active_record_bitemporal_original_reload, :reload unless method_defined? :active_record_bitemporal_original_reload
Expand Down

0 comments on commit 0bd3a34

Please sign in to comment.