Skip to content

Instantly share code, notes, and snippets.

@carllerche
Created January 30, 2009 20:08
Show Gist options
  • Save carllerche/55235 to your computer and use it in GitHub Desktop.
Save carllerche/55235 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -KU
require "rubygems"
require "dm-core"
DataMapper.setup(:default, 'sqlite3::memory:')
DataMapper.setup(:second, "sqlite3:///#{File.dirname(__FILE__)}/test.db")
class Customer
include DataMapper::Resource
def self.default_repository_name ; :default ; end
property :id, Serial
property :name, String
def contact
DataMapper.repository(:second) do
Contact.first(:name => name)
end
end
end
class Contact
include DataMapper::Resource
def self.default_repository_name ; :second ; end
property :id, Serial
property :name, String
end
Customer.auto_migrate!(:default)
Contact.auto_migrate!(:second)
# Customer.create(:name => "carl") # DataMapper.repository(:default) { }
Contact.create(:name => "carl") # DataMapper.repository(:second) { }
customer = Customer.new(:name => "carl")
customer.contact
puts customer.class.repositories.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment