mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
parent
445c12f7df
commit
01421d5b62
1 changed files with 8 additions and 4 deletions
|
@ -305,15 +305,19 @@ module ActiveRecord
|
|||
_run_initialize_callbacks
|
||||
end
|
||||
|
||||
# Initialize an empty model object from +coder+. +coder+ must contain
|
||||
# the attributes necessary for initializing an empty model object. For
|
||||
# example:
|
||||
# Initialize an empty model object from +coder+. +coder+ should be
|
||||
# the result of previously encoding an Active Record model, using
|
||||
# `encode_with`
|
||||
#
|
||||
# class Post < ActiveRecord::Base
|
||||
# end
|
||||
#
|
||||
# old_post = Post.new(title: "hello world")
|
||||
# coder = {}
|
||||
# old_post.encode_with(coder)
|
||||
#
|
||||
# post = Post.allocate
|
||||
# post.init_with('attributes' => { 'title' => 'hello world' })
|
||||
# post.init_with(coder)
|
||||
# post.title # => 'hello world'
|
||||
def init_with(coder)
|
||||
coder = LegacyYamlAdapter.convert(self.class, coder)
|
||||
|
|
Loading…
Reference in a new issue