Skip to content

Instantly share code, notes, and snippets.

@gugod
Created September 16, 2010 16:58
Show Gist options
  • Save gugod/582753 to your computer and use it in GitHub Desktop.
Save gugod/582753 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'dm-core'
require 'dm-types'
require 'dm-migrations'
require 'dm-is-remixable'
DataMapper.setup(:default, 'mysql://root@localhost/dm_remixable_test')
#########################################################################################################
module Comment
include DataMapper::Resource
is :remixable
property :id, Serial
property :body, String
property :created_at, DateTime
end
module Addressable
include DataMapper::Resource
is :remixable, :suffix => "address"
property :id, Serial
property :label, String #home, work, etc...
property :address1, String, :length => 255
property :address2, String, :length => 255
property :city, String, :length => 128
property :state, String, :length => 2
property :zip, String, :length => 5..10
end
module Vote
include DataMapper::Resource
is :remixable
property :id, Serial
property :opinion, Enum["good","bad"]
end
class Location
include DataMapper::Resource
remix 1, :addressables
property :id, Serial
end
class User
include DataMapper::Resource
remix n, :addressables, :as => "addresses"
enhance :addressables do
property :label, Enum["work","home"]
end
property :id, Serial
end
class Article
include DataMapper::Resource
remix n, :comments, :for => "User"
property :id, Serial
end
class Video
include DataMapper::Resource
remix n, :comments, :for => "User", :as => "comments"
enhance :comments do
def reverse
return self.body.reverse
end
remix 1, :votes, :for => "User"
end
property :id, Serial
end
#########################################################################################################
DataMapper.auto_migrate!
> ruby dm-is-remixable-example.rb
/usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/associations/relationship.rb:173:in `target_model': Cannot find the child_model VideoCommentVotes for User in video_comment_votes (NameError)
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/associations/relationship.rb:391:in `inverse'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/associations/one_to_many.rb:22:in `child_key'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/associations/one_to_one.rb:81:in `send'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/associations/one_to_one.rb:81:in `method_missing'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:793:in `assert_valid'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:792:in `each'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:792:in `assert_valid'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:791:in `each'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:791:in `assert_valid'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:128:in `auto_migrate!'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:45:in `send'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:45:in `repository_execute'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/support/descendant_set.rb:68:in `each'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/support/descendant_set.rb:67:in `each'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:44:in `repository_execute'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:22:in `auto_migrate!'
from dm-is-remixable-example.rb:92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment