Skip to content

Instantly share code, notes, and snippets.

@kaichen
Created January 13, 2010 09:30
Show Gist options
  • Save kaichen/276068 to your computer and use it in GitHub Desktop.
Save kaichen/276068 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core' # DM v0.10.2
DataMapper.logger = DataMapper::Logger.new($stderr, :debug)
DataMapper.setup(:default, 'mysql://localhost/for_testing')
class Comment
include DataMapper::Resource
property :id, Serial
property :content, String
property :rate, Integer
end
DataMapper.auto_migrate!
comment = Comment.new(:content => 'hey hey hey', :rate => '')
p comment.save
p comment.errors
#~ (0.000003) SET sql_auto_is_null = 0
#~ (0.000001) SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
#~ (0.000001) DROP TABLE IF EXISTS `comments`
#~ (0.000002) SHOW TABLES LIKE 'comments'
#~ (0.000001) SHOW VARIABLES LIKE 'character_set_connection'
#~ (0.000001) SHOW VARIABLES LIKE 'collation_connection'
#~ (0.000002) CREATE TABLE `comments` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `content` VARCHAR(50), `rate` INTEGER, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
#~ (0.000002) INSERT INTO `comments` (`content`, `rate`) VALUES ('hey hey hey', '')
#~ Incorrect integer value: '' for column 'rate' at row 1 (code: 1366, sql state: HY000, query: INSERT INTO `comments` (`content`, `rate`) VALUES ('hey hey hey', ''), uri: mysql://localhost/for_testing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment