Skip to content

Commit

Permalink
Exclude record valid range end in uniqueness validation
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Dec 24, 2024
1 parent 143bbd2 commit 495a120
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/activerecord-bitemporal/bitemporal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ def scope_relation(record, relation)
# レコードを更新する時に valid_datetime が valid_from ~ valid_to の範囲外だった場合、
# 一番近い未来の履歴レコードを参照して更新する
# という仕様があるため、それを考慮して valid_to を設定する
if (record_valid_time && (record.valid_from..record.valid_to).cover?(record_valid_time)) == false && (record.persisted?)
finder_class.ignore_valid_datetime.where(bitemporal_id: record.bitemporal_id).valid_from_gt(target_datetime).order(valid_from: :asc).first.valid_from
if (record_valid_time && (record.valid_from...record.valid_to).cover?(record_valid_time)) == false && (record.persisted?)
finder_class.ignore_valid_datetime.where(bitemporal_id: record.bitemporal_id).valid_from_gteq(target_datetime).order(valid_from: :asc).first.valid_from
else
valid_to
end
Expand Down

0 comments on commit 495a120

Please sign in to comment.