Created
October 1, 2010 01:20
-
-
Save kematzy/605576 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
| require 'rubygems' | |
| require 'dm-sqlite-adapter' | |
| require 'data_mapper' | |
| class Test | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :title, String, :length => 255 | |
| property :description, String, :length => 255 | |
| end | |
| DataMapper.setup( :default, "sqlite3::memory:" ) | |
| DataMapper.auto_migrate! | |
| create_new_record = Test.first_or_create( | |
| 'title' => 'A', | |
| 'description' => 'B' | |
| ) | |
| if create_new_record.save | |
| puts "New Record was saved: [#{create_new_record.inspect}]" | |
| else | |
| puts "New Record was NOT saved: [#{create_new_record.inspect}]" | |
| end | |
| use_first_record = Test.first_or_create( | |
| 'title' => 'A', | |
| 'description' => 'B' | |
| ) | |
| if use_first_record.save | |
| puts "First Record was 'saved': [#{use_first_record.inspect}]" | |
| else | |
| puts "First Record was NOT saved: [#{use_first_record.inspect}]" | |
| end | |
| puts "\nTest.all =[#{Test.all.inspect}]" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment