Created
June 18, 2009 19:55
-
-
Save ashgti/132153 to your computer and use it in GitHub Desktop.
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
| #!ruby | |
| require 'rubygems' | |
| require 'dm-core' | |
| require 'dm-timestamps' | |
| require 'dm-is-versioned' | |
| DataMapper::Logger.new(STDOUT, :debug) | |
| DataMapper.setup(:default, "mysql://root:password@localhost/db_testing") | |
| class Post | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :title, String | |
| property :type, Discriminator | |
| property :updated_at, DateTime | |
| timestamps :at | |
| class << self | |
| # def storage_name repo | |
| # 'contents' | |
| # end | |
| end | |
| is_versioned :on => :updated_at | |
| end | |
| class Comment < Post | |
| property :content, Text | |
| end | |
| Post.auto_migrate! | |
| Comment.auto_migrate! | |
| post = Post.new | |
| post.title = 'one' | |
| post.save | |
| sleep 5 | |
| post.title = 'changed' | |
| # post.updated_at = Time.new + 10000 | |
| post.save | |
| comment = Comment.new | |
| comment.content = 'hi' | |
| comment.title = 'yes' | |
| comment.save | |
| comment.content = 'changed, should make a new version' | |
| comment.save | |
| p comment.versions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment