Module: ActiveRecord::Marshalling::Methods

Included in:
Base
Defined in:
lib/active_record/marshalling.rb

Instance Method Summary collapse

Instance Method Details

#_marshal_dump_7_1Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_record/marshalling.rb', line 24

def _marshal_dump_7_1
  payload = [attributes_for_database, new_record?]

  cached_associations = self.class.reflect_on_all_associations.select do |reflection|
    association_cached?(reflection.name) && association(reflection.name).loaded?
  end

  unless cached_associations.empty?
    payload << cached_associations.map do |reflection|
      [reflection.name, association(reflection.name).target]
    end
  end

  payload
end

#marshal_load(state) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/active_record/marshalling.rb', line 40

def marshal_load(state)
  attributes_from_database, new_record, associations = state

  attributes = self.class.attributes_builder.build_from_database(attributes_from_database)
  init_with_attributes(attributes, new_record)

  if associations
    associations.each do |name, target|
      association(name).target = target
    rescue ActiveRecord::AssociationNotFoundError
      # the association no longer exist, we can just skip it.
    end
  end
end