Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Created September 4, 2009 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baroquebobcat/180961 to your computer and use it in GitHub Desktop.
Save baroquebobcat/180961 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'datamapper'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
class A
include DataMapper::Resource
property :id,Serial
has n, :bs
end
class B
include DataMapper::Resource
property :id,Serial
belongs_to :aa,:class_name=>'A',:child_key=>[:aa_id]
def z
self.aa = A.new
end
before :valid?, :z
end
DataMapper.auto_migrate!
x = B.new
x.aa = A.new
x.save
p B.first.aa.bs
#=> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment