@@ -64,6 +64,16 @@ def table_exists?
6464 true
6565 end
6666
67+ # Stub connection for ActiveRecord::Timestamp compatibility
68+ def connection
69+ @connection ||= Struct . new ( :default_timezone ) . new ( :utc )
70+ end
71+
72+ # ActiveRecord 7.1 compatibility
73+ def composite_primary_key?
74+ false
75+ end
76+
6777 def _reflect_on_association ( _attribute )
6878 false
6979 end
@@ -85,12 +95,30 @@ def attribute_names
8595 attribute_types . keys
8696 end
8797 end
98+
99+ # Rails 7.1+ renamed generate_alias_attributes to generate_alias_attribute_methods
100+ # ActiveRecord still calls the old method name, so we need to provide compatibility
101+ # The old method had no parameters, so we just provide an empty implementation
102+ if ActiveModel ::VERSION ::MAJOR >= 7 && ActiveModel ::VERSION ::MINOR >= 1
103+ def generate_alias_attributes ( *args )
104+ # In Rails 7.1+, this method was renamed and signature changed
105+ # ActiveRecord 7.1 still calls it with no args, so we handle that case
106+ return if args . empty?
107+
108+ generate_alias_attribute_methods ( *args )
109+ end
110+ end
88111 end
89112
90113 def _has_attribute? ( attr_name )
91114 attribute_names . include? ( attr_name . to_s )
92115 end
93116
117+ # ActiveRecord 7.1 compatibility
118+ def primary_key_values_present?
119+ !id . nil?
120+ end
121+
94122 def attribute_for_inspect ( attr_name )
95123 value = send ( attr_name )
96124 value . inspect
@@ -136,6 +164,17 @@ def read_attribute(attr_name, &block)
136164 end
137165
138166 class Document
167+ class << self
168+ def descendants
169+ @__descendants ||= [ ] # rubocop:disable Naming/MemoizedInstanceVariableName
170+ end
171+
172+ def inherited ( subclass )
173+ super
174+ descendants << subclass
175+ end
176+ end
177+
139178 include ::ActiveModel ::Model
140179 include ::ActiveModel ::Dirty
141180 include ::ActiveModel ::Attributes
@@ -154,6 +193,9 @@ class Document
154193 define_model_callbacks :initialize , :find , only : :after
155194 define_model_callbacks :create , :destroy , :save , :update
156195
196+ # Prevent duplicate validation errors (similar to ActiveRecord::AutosaveAssociation)
197+ after_validation :_ensure_no_duplicate_errors
198+
157199 Metadata = Struct . new ( :cas )
158200
159201 class MismatchTypeError < RuntimeError ; end
@@ -218,6 +260,10 @@ def write_attribute(attr_name, value)
218260
219261 @attributes . write_from_user ( name , value )
220262 end
263+
264+ def _ensure_no_duplicate_errors
265+ errors . uniq!
266+ end
221267 end
222268
223269 class NestedDocument < Document
0 commit comments