Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 7.01 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'dm-core'
  2. require 'dm-migrations'
  3. require 'dm-validations'
  4.  
  5. DataMapper::Logger.new($stdout, :debug)
  6. DataMapper.setup(:default, 'mysql://root@localhost/test')
  7.  
  8. module Camino
  9.   module Business
  10.  
  11.     class Branch
  12.  
  13.       include DataMapper::Resource
  14.  
  15.       property :id, Serial
  16.  
  17.       has n, :business_years, 'Camino::Business::Year'
  18.  
  19.     end
  20.  
  21.     class Year
  22.  
  23.       include DataMapper::Resource
  24.  
  25.       property :start, Date, :required => true, :unique => :years
  26.       property :stop,  Date, :required => true, :unique => :years
  27.  
  28.       belongs_to :branch, 'Camino::Business::Branch', :key => true
  29.  
  30.     end
  31.   end
  32. end
  33.  
  34. DataMapper.finalize.auto_migrate!
  35.  
  36. Camino::Business::Branch.create :business_years => [
  37.   Camino::Business::Year.new(:start => Date.today, :stop => Date.today + 150)
  38. ]
  39.  
  40. __END__
  41.  
  42. ree-1.8.7-2010.02 mungo:camino_surf snusnu$ bundle exec ruby foo.rb
  43.  ~ (0.000098) SET sql_auto_is_null = 0
  44.  ~ (0.000078) SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
  45.  ~ (0.001577) DROP TABLE IF EXISTS `camino_business_branches`
  46.  ~ (0.000253) SHOW TABLES LIKE 'camino_business_branches'
  47.  ~ (0.000083) SET sql_auto_is_null = 0
  48.  ~ (0.000084) SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
  49.  ~ (0.000306) SHOW VARIABLES LIKE 'character_set_connection'
  50.  ~ (0.000289) SHOW VARIABLES LIKE 'collation_connection'
  51.  ~ (0.141534) CREATE TABLE `camino_business_branches` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
  52.  ~ (0.002576) DROP TABLE IF EXISTS `camino_business_years`
  53.  ~ (0.000297) SHOW TABLES LIKE 'camino_business_years'
  54.  ~ (0.194693) CREATE TABLE `camino_business_years` (`start` DATE NOT NULL, `stop` DATE NOT NULL, `branch_id` INT(10) UNSIGNED NOT NULL, PRIMARY KEY(`branch_id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
  55.  ~ (0.136234) CREATE INDEX `index_camino_business_years_branch` ON `camino_business_years` (`branch_id`)
  56.  ~ (0.143769) CREATE UNIQUE INDEX `unique_camino_business_years_years` ON `camino_business_years` (`start`, `stop`)
  57.  ~ (0.001048) INSERT INTO `camino_business_branches` () VALUES ()
  58. /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/validators/uniqueness_validator.rb:36:in `__send__': undefined method `years' for #<Camino::Business::Year:0x101e7e468> (NoMethodError)
  59.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/validators/uniqueness_validator.rb:36:in `valid?'
  60.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/validators/uniqueness_validator.rb:36:in `each'
  61.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/validators/uniqueness_validator.rb:36:in `valid?'
  62.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/validators/uniqueness_validator.rb:19:in `call'
  63.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/contextual_validators.rb:58:in `execute'
  64.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/contextual_validators.rb:57:in `map'
  65.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/contextual_validators.rb:57:in `execute'
  66.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations.rb:137:in `valid?'
  67.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations.rb:108:in `save_self'
  68.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1018:in `_save'
  69.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1234:in `run_once'
  70.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1017:in `_save'
  71.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:417:in `save'
  72.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations.rb:96:in `save'
  73.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/support/context.rb:30:in `validation_context'
  74.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations.rb:96:in `save'
  75.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/collection.rb:1241:in `__send__'
  76.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/collection.rb:1241:in `_save'
  77.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/gems/data_objects-0.10.2/lib/data_objects/connection.rb:136:in `all?'
  78.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/collection.rb:1241:in `each'
  79.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/collection.rb:1241:in `all?'
  80.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/collection.rb:1241:in `_save'
  81.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/associations/one_to_many.rb:274:in `_save'
  82.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/collection.rb:873:in `save'
  83.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1066:in `__send__'
  84.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1066:in `save_children'
  85.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1065:in `map'
  86.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1065:in `save_children'
  87.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1018:in `_save'
  88.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1234:in `run_once'
  89.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:1017:in `_save'
  90.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-core-75c67e6/lib/dm-core/resource.rb:417:in `save'
  91.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations.rb:96:in `save'
  92.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations/support/context.rb:30:in `validation_context'
  93.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations.rb:96:in `save'
  94.         from /Users/snusnu/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/dm-validations-1211e58/lib/dm-validations.rb:81:in `create'
  95.         from foo.rb:36