· 8 years ago · Apr 07, 2018, 08:30 AM
1require 'rubygems'
2require 'dm-core' # DM v0.10.2
3DataMapper.logger = DataMapper::Logger.new($stderr, :debug)
4DataMapper.setup(:default, 'mysql://localhost/for_testing')
5
6class Comment
7 include DataMapper::Resource
8
9 property :id, Serial
10 property :content, String
11 property :rate, Integer
12end
13
14DataMapper.auto_migrate!
15
16comment = Comment.new(:content => 'hey hey hey', :rate => '')
17p comment.save
18p comment.errors
19
20#~ (0.000003) SET sql_auto_is_null = 0
21#~ (0.000001) SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
22#~ (0.000001) DROP TABLE IF EXISTS `comments`
23#~ (0.000002) SHOW TABLES LIKE 'comments'
24#~ (0.000001) SHOW VARIABLES LIKE 'character_set_connection'
25#~ (0.000001) SHOW VARIABLES LIKE 'collation_connection'
26#~ (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
27#~ (0.000002) INSERT INTO `comments` (`content`, `rate`) VALUES ('hey hey hey', '')
28#~ 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)