2008年11月10日 星期一

clone

http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001761


Returns a clone of the record that hasn‘t been assigned an id yet and is treated as a new record. Note that this is a "shallow" clone: it copies the object‘s attributes only, not its associations. The extent of a "deep" clone is application-specific and is therefore left to the application to implement according to its need.


>> u = User.first
=> #<User id: 1, name: "ilake", created_at: "2008-11-04 00:31:17", updated_at: "2008-11-04 00:31:17">
>> uc = u.clone
=> #<User id: nil, name: "ilake", created_at: "2008-11-04 00:31:17", updated_at: "2008-11-04 00:31:17">
>> uc.books
=> []
>> uc.name
=> "ilake"
>> uc.new_record?
=> true

沒有留言: