方法
类公共方法
new(entries) 链接
源代码: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/message_pack.rb, line 91 def initialize(entries) @records = entries.map { |entry| build_record(entry) } @records.zip(entries) { |record, entry| resolve_cached_associations(record, entry) } end
实例公共方法
build_record(entry) 链接
源代码: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/message_pack.rb, line 104 def build_record(entry) class_name, attributes_hash, is_new_record, * = entry klass = ActiveSupport::MessagePack::Extensions.load_class(class_name) attributes = klass.attributes_builder.build_from_database(attributes_hash) klass.allocate.init_with_attributes(attributes, is_new_record) end
decode(ref) 链接
源代码: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/message_pack.rb, line 96 def decode(ref) if ref.is_a?(Array) ref.map { |r| @records[r] } elsif ref @records[ref] end end
resolve_cached_associations(record, entry) 链接
源代码: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/message_pack.rb, line 111 def resolve_cached_associations(record, entry) i = 3 # entry == [class_name, attributes_hash, is_new_record, *associations] while i < entry.length begin record.association(entry[i]).target = decode(entry[i + 1]) rescue ActiveRecord::AssociationNotFoundError # The association no longer exists, so just skip it. end i += 2 end end