Module: RactorRailsShim::ActiveRecordAttributesPatch::InstanceMethods
- Defined in:
- lib/ractor_rails_shim/patches/active_model_attribute.rb
Instance Method Summary collapse
-
#_default_attributes ⇒ Object
ActiveRecord overrides _default_attributes (attributes.rb:253) with a version that reads the @default_attributes class ivar and opens a connection to build the AttributeSet.
Instance Method Details
#_default_attributes ⇒ Object
ActiveRecord overrides _default_attributes (attributes.rb:253) with a version that reads the @default_attributes class ivar and opens a connection to build the AttributeSet. Same per-Ractor fix as above: cache in IES so workers never read/write the shared class ivar.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ractor_rails_shim/patches/active_model_attribute.rb', line 80 def _default_attributes # :nodoc: key = :"rrs_default_attributes_#{object_id}" ActiveSupport::IsolatedExecutionState[key] ||= begin attributes_hash = with_connection do |connection| columns_hash.transform_values do |column| ::ActiveModel::Attribute.from_database( column.name, column.default, type_for_column(connection, column) ) end end attribute_set = ::ActiveModel::AttributeSet.new(attributes_hash) apply_pending_attribute_modifications(attribute_set) attribute_set end end |