Skip to content

Commit 57b27b1

Browse files
committed
Support rails 7.2
rails/rails@e0a55b0 While we do not leverage the `attribute` api, we are strongly influenced by it. We do not want a default value record, which modifies select(*) calls and others. We want to add the values to `attribute_type`. Before ------ The values are stored in `attributes_to_define_after_schema_loads` at class load time, and in load_schema, are then used to generate entries for `DefaultValue` and `attribute_type`. After ----- The values are stored as `ModifyAttribute` entries. Those values then are used to populate default values and attribute_type on demand. Our Change ---------- Previous PRs removed arel and uses logic so load_schema only manipulated attribute_type. Like the rails change, we populate (modify) attribute_type on demand.
1 parent 23ad9ad commit 57b27b1

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
source "https://rubygems.org"
44

5-
gem "activerecord", "~>7.1.5"
65
gem "mysql2"
76
gem "pg"
87
gem "sqlite3", "< 2"

activerecord-virtual_attributes.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
2828

2929
spec.require_paths = ["lib"]
3030

31-
spec.add_runtime_dependency "activerecord", "~> 7.1", ">=7.1.5.1"
31+
spec.add_runtime_dependency "activerecord", "~> 7.2.2", ">=7.2.2.1"
3232

3333
spec.add_development_dependency "byebug"
3434
spec.add_development_dependency "database_cleaner-active_record", "~> 2.1"

lib/active_record/virtual_attributes.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,13 @@ def virtual_attribute_names
8787
end
8888
end
8989

90-
private
91-
92-
def load_schema!
93-
super
94-
95-
virtual_attributes_to_define.each do |name, (type, options)|
96-
type = type.call if type.respond_to?(:call)
97-
type = ActiveRecord::Type.lookup(type, **options) if type.kind_of?(Symbol)
98-
99-
define_virtual_attribute(name, type)
90+
def attribute_types
91+
@attribute_types || super.tap do |hash|
92+
virtual_attributes_to_define.each do |name, (type, options)|
93+
type = type.call if type.respond_to?(:call)
94+
type = ActiveRecord::Type.lookup(type, **options) if type.kind_of?(Symbol)
95+
hash[name] = type
96+
end
10097
end
10198
end
10299

0 commit comments

Comments
 (0)