# encoding: utf-8
require 'rubygems'
require 'dm-core'
DataMapper.setup(:default,
:adapter => 'mysql',
:host => 'localhost',
:username => 'root',
:database => 'dm_core_test',
:encoding => 'UTF-8'
)
DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, :debug)
class Company
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :invoices, :child_key => [:owner_id]
end
class Invoice
include DataMapper::Resource
property :id, Serial
property :nr, Integer
belongs_to :owner, :model => "Company", :child_key => [:owner_id]
end
DataMapper.auto_migrate!
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000078) SET sql_auto_is_null = 0
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000075) SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.079298) DROP TABLE IF EXISTS `companies`
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.002240) DROP TABLE IF EXISTS `invoices`
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000273) SHOW TABLES LIKE 'companies'
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000296) SHOW VARIABLES LIKE 'character_set_connection'
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000249) SHOW VARIABLES LIKE 'collation_connection'
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.080663) CREATE TABLE `companies` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(50), PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000250) SHOW TABLES LIKE 'invoices'
# Sun, 25 Oct 2009 14:00:44 GMT ~ debug ~ (0.173635) CREATE TABLE `invoices` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `nr` INTEGER, `owner_id` INT(10) UNSIGNED NOT NULL, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
# Sun, 25 Oct 2009 14:00:44 GMT ~ debug ~ (0.154411) CREATE INDEX `index_invoices_owner` ON `invoices` (`owner_id`)
# /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:72:in `execute_non_query': Field 'owner_id' doesn't have a default value (DataObjects::SQLError)
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:72:in `block in execute'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:283:in `with_connection'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:70:in `execute'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:119:in `block in create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:92:in `each'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:92:in `create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/repository.rb:124:in `create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:877:in `_create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:669:in `create_hook'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/hook.rb:299:in `block in create_hook'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/hook.rb:297:in `catch'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/hook.rb:297:in `create_hook'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:553:in `save_self'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:927:in `_save'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:344:in `save'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/model.rb:610:in `_create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/model.rb:401:in `create'
# from domigrate.rb:52:in `<main>'