Skip to content

Instantly share code, notes, and snippets.

@lumpidu
Created May 16, 2011 20:51
Show Gist options
  • Save lumpidu/975349 to your computer and use it in GitHub Desktop.
Save lumpidu/975349 to your computer and use it in GitHub Desktop.
DataMapper multiple Contexts: Error Case
#!/usr/bin/env ruby
#
require 'rubygems'
require 'data_mapper'
class Feed
include DataMapper::Resource
property :id, Serial
has n, :posts, :through => Resource
has n, :failed_posts, :through => Resource
end
class Post
include DataMapper::Resource
property :id, Serial
has 1, :feed, :through => Resource
has 1, :conversion
end
class FailedPost
include DataMapper::Resource
property :id, Serial
property :title, Text, :required => true
has 1, :feed, :through => Resource
end
class Conversion
include DataMapper::Resource
property :id, Serial
belongs_to :post
end
class RssModel
attr_reader :our_context
def initialize(option={})
path = option[:path]
our_context = option[:context]
our_context ||= :default # if none provided, context is :default
DataMapper.setup(our_context, "#{path}")
DataMapper.repository(our_context) {
DataMapper.finalize
DataMapper.auto_upgrade!
}
end
end
src_model=RssModel.new(:path => "sqlite://tmp/testdb.sqlite")
dest_model=RssModel.new(:path => "postgres://user:password@localhost/testdb", :context => :dest_db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment