somebee (owner)

Revisions

gist: 210142 Download_button fork
public
Public Clone URL: git://gist.github.com/210142.git
Embed All Files: show embed
out.txt #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.000145) SET sql_auto_is_null = 0
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.000070) SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.001966) DROP TABLE IF EXISTS `phones`
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.002025) DROP TABLE IF EXISTS `companies`
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.000220) SHOW TABLES LIKE 'phones'
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.000303) SHOW VARIABLES LIKE 'character_set_connection'
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.000227) SHOW VARIABLES LIKE 'collation_connection'
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.085831) CREATE TABLE `phones` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `nr` VARCHAR(50), `company_id` INT(10) UNSIGNED NOT NULL, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET latin1 COLLATE latin1_swedish_ci
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.225961) CREATE INDEX `index_phones_company` ON `phones` (`company_id`)
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.000303) SHOW TABLES LIKE 'companies'
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.103740) CREATE TABLE `companies` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(50), `main_phone_id` INT(10) UNSIGNED NOT NULL, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET latin1 COLLATE latin1_swedish_ci
Wed, 14 Oct 2009 15:06:07 GMT ~ debug ~ (0.104512) CREATE INDEX `index_companies_main_phone` ON `companies` (`main_phone_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 'main_phone_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:287: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:125: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:831: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:632: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:550: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:338: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:616: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:403:in `create'
from relationship_3.rb:34:in `<main>'
 
relationship_3.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 Phone
  include DataMapper::Resource
  
  property :id, Serial
  property :nr, String
  
  belongs_to :company
end
 
class Company
  include DataMapper::Resource
  property :id, Serial
  property :name, String
  
  belongs_to :main_phone, :model => Phone
  has n, :phones
end
 
DataMapper.auto_migrate!
 
c = Company.create :name => 'Whole Foods'
 
c.phones.create :nr => "12345"
c.phones.create :nr => "23456"
 
p = c.phones.new :nr => "10000"
c.main_phone = p
p.save