Created
October 13, 2011 11:25
-
-
Save solnic/1284006 to your computer and use it in GitHub Desktop.
improved_dirty_tracking_in_dm_1.2.0.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'data_mapper' | |
DataMapper.setup :default, 'sqlite::memory:' | |
class Book | |
include DataMapper::Resource | |
property :id, Serial | |
property :meta, Json | |
end | |
DataMapper.finalize.auto_migrate! | |
Book.create(:meta => { :title => 'Some Title' }) | |
book = Book.first | |
book.meta['title'] # 'Some Title' | |
book.meta['title'] = 'Other Title' | |
puts book.dirty? | |
puts book.dirty_attributes | |
# -------------------------------------------------------------------------------------- | |
# Output: | |
# | |
# true | |
# {#<DataMapper::Property::Json @model=Book @name=:meta>=>"{\"title\":\"Other Title\"}"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment