HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/ruby-2.7.4/doc/activerecord-6.1.4.1/ri/ActiveRecord/Store/cdesc-Store.ri
U:RDoc::NormalModule[iI"
Store:ETI"ActiveRecord::Store;T0o:RDoc::Markup::Document:@parts[o;;[ o:RDoc::Markup::Paragraph;[I"kStore gives you a thin wrapper around serialize for the purpose of storing hashes in a single column. ;TI"gIt's like a simple key/value store baked into your record when you don't care about being able to ;TI"=query that store outside the context of a single record.;To:RDoc::Markup::BlankLineo;	;[I"iYou can then declare accessors to this store that are then accessible just like any other attribute ;TI"eof the model. This is very helpful for easily exposing store keys to a form or elsewhere that's ;TI"Aalready built around just accessing attributes on the model.;T@o;	;[I"gEvery accessor comes with dirty tracking methods (+key_changed?+, +key_was+ and +key_change+) and ;TI"pmethods to access the changes made during the last save (+saved_change_to_key?+, +saved_change_to_key+ and ;TI"+key_before_last_save+).;T@o;	;[I"aNOTE: There is no +key_will_change!+ method for accessors, use +store_will_change!+ instead.;T@o;	;[I"hMake sure that you declare the database column used for the serialized store as a text, so there's ;TI"plenty of room.;T@o;	;[I"eYou can set custom coder to encode/decode your serialized attributes to/from different formats. ;TI"wJSON, YAML, Marshal are supported out of the box. Generally it can be any wrapper that provides +load+ and +dump+.;T@o;	;[
I"kNOTE: If you are using structured database data types (e.g. PostgreSQL +hstore+/+json+, or MySQL 5.7+ ;TI"p+json+) there is no need for the serialization provided by {.store}[rdoc-ref:rdoc-ref:ClassMethods#store]. ;TI"\Simply use {.store_accessor}[rdoc-ref:ClassMethods#store_accessor] instead to generate ;TI"gthe accessor methods. Be aware that these columns use a string keyed hash and do not allow access ;TI"using a symbol.;T@o;	;[I"QNOTE: The default validations with the exception of +uniqueness+ will work. ;TI"OFor example, if you want to check for +uniqueness+ with +hstore+ you will ;TI"2need to use a custom validation to handle it.;T@o;	;[I"Examples:;T@o:RDoc::Markup::Verbatim;[%I"%class User < ActiveRecord::Base
;TI"F  store :settings, accessors: [ :color, :homepage ], coder: JSON
;TI"F  store :parent, accessors: [ :name ], coder: JSON, prefix: true
;TI"J  store :spouse, accessors: [ :name ], coder: JSON, prefix: :partner
;TI"F  store :settings, accessors: [ :two_factor_auth ], suffix: true
;TI"E  store :settings, accessors: [ :login_retry ], suffix: :config
;TI"	end
;TI"
;TI"hu = User.new(color: 'black', homepage: '37signals.com', parent_name: 'Mary', partner_name: 'Lily')
;TI"Bu.color                          # Accessor stored attribute
;TI"Nu.parent_name                    # Accessor stored attribute with prefix
;TI"Uu.partner_name                   # Accessor stored attribute with custom prefix
;TI"Nu.two_factor_auth_settings       # Accessor stored attribute with suffix
;TI"Uu.login_retry_config             # Accessor stored attribute with custom suffix
;TI"^u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
;TI"
;TI"Z# There is no difference between strings and symbols for accessing custom attributes
;TI"*u.settings[:country]  # => 'Denmark'
;TI"*u.settings['country'] # => 'Denmark'
;TI"
;TI"# Dirty tracking
;TI"u.color = 'green'
;TI" u.color_changed? # => true
;TI"u.color_was # => 'black'
;TI"*u.color_change # => ['black', 'red']
;TI"
;TI"L# Add additional accessors to an existing store through store_accessor
;TI"class SuperUser < User
;TI"8  store_accessor :settings, :privileges, :servants
;TI"7  store_accessor :parent, :birthday, prefix: true
;TI"C  store_accessor :settings, :secret_question, suffix: :config
;TI"	end
;T:@format0o;	;[I"~The stored attribute names can be retrieved using {.stored_attributes}[rdoc-ref:rdoc-ref:ClassMethods#stored_attributes].;T@o;;[I"]User.stored_attributes[:settings] # [:color, :homepage, :two_factor_auth, :login_retry]
;T;0S:RDoc::Markup::Heading:
leveli:	textI""Overwriting default accessors;T@o;	;[	I"ZAll stored values are automatically available through accessors on the Active Record ;TI"aobject, but sometimes you want to specialize this behavior. This can be done by overwriting ;TI"]the default accessors (using the same name as the attribute) and calling <tt>super</tt> ;TI"to actually change things.;T@o;;[I"%class Song < ActiveRecord::Base
;TI"I  # Uses a stored integer to hold the volume adjustment of the song
;TI"8  store :settings, accessors: [:volume_adjustment]
;TI"
;TI"(  def volume_adjustment=(decibels)
;TI"    super(decibels.to_i)
;TI"  end
;TI"
;TI"  def volume_adjustment
;TI"    super.to_i
;TI"  end
;TI"end;T;0:
@fileI"lib/active_record/store.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[[
I"local_stored_attributes;TI"RW;T:publicTI"lib/active_record/store.rb;T[[[[I"
class;T[[;[[:protected[[:private[[I"
instance;T[[;[[;[[;[[I"read_store_attribute;T@z[I"store_accessor_for;T@z[I"write_store_attribute;T@z[[I"ActiveSupport::Concern;To;;[;@u;0@z[U:RDoc::Context::Section[i0o;;[;0;0[@uI"#lib/active_record/type/json.rb;TI")lib/active_record/type/serialized.rb;TI"ActiveRecord;TcRDoc::NormalModule