跳至内容 跳至搜索
方法
#
M

实例公共方法

_marshal_dump_7_1()

# File activerecord/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|
    if association_cached?(reflection.name)
      association = association(reflection.name)
      association.loaded? || association.target.present?
    end
  end

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

  payload
end

marshal_load(state)

# File activerecord/lib/active_record/marshalling.rb, line 43
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