Module: ActiveRecord::Embedded::Model
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Model, Attributes, Fields, Indexing, Persistence, Querying, Storage, Integration, Comparable
- Defined in:
- lib/active_record/embedded/model.rb,
lib/active_record/embedded/model/fields.rb,
lib/active_record/embedded/model/storage.rb,
lib/active_record/embedded/model/indexing.rb,
lib/active_record/embedded/model/querying.rb,
lib/active_record/embedded/model/attributes.rb,
lib/active_record/embedded/model/persistence.rb
Overview
Mix this into your embedded model classes to provide ActiveRecord::Embedded
functionality, including field/index definition, validations, callbacks, and AR-style fields like timestamps and identifiers.
Defined Under Namespace
Modules: Attributes, Fields, Indexing, Persistence, Querying, Storage
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Another record is equal to this model if its
#id
is the same. -
#cache_key(*timestamp_names) ⇒ String
Prefix the embedded model’s cache key with the parent model’s cache key.
- #initialize(uncased = {}, _parent: nil, _association: nil, **params) ⇒ Object
Methods included from Persistence
#destroy, #destroy!, #new_record?, #persisted?, #reload, #save, #save!, #update, #update!, #valid?
Methods included from Attributes
#[], #[]=, #assign_attributes, #inspect, #key?
Instance Method Details
#==(other) ⇒ Boolean
Another record is equal to this model if its #id
is the same.
42 43 44 45 46 |
# File 'lib/active_record/embedded/model.rb', line 42 def ==(other) return false if id.blank? id == other&.id end |
#cache_key(*timestamp_names) ⇒ String
Prefix the embedded model’s cache key with the parent model’s cache key.
53 54 55 |
# File 'lib/active_record/embedded/model.rb', line 53 def cache_key(*) "#{_parent.cache_key}/#{super}" end |
#initialize(uncased = {}, _parent: nil, _association: nil, **params) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/active_record/embedded/model.rb', line 29 def initialize(uncased = {}, _parent: nil, _association: nil, **params) @_parent = _parent || params[parent_model.name] @_association = _association @attributes = amalgamate_attributes(uncased, params) run_callbacks :initialize do super(attributes) end end |