Skip to content

Instantly share code, notes, and snippets.

@xxx
Created October 7, 2009 05:01
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 xxx/203774 to your computer and use it in GitHub Desktop.
Save xxx/203774 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'dm-core'
require 'dm-sweatshop'
class Foo
include DataMapper::Resource
property :id, Serial
has n, :bars
belongs_to :current_bar, :model => 'Bar', :child_key => [:current_bar_id], :nullable => true
end
class Bar
include DataMapper::Resource
property :id, Serial
belongs_to :foo, :nullable => true
has n, :bazs
end
class Baz
include DataMapper::Resource
property :id, Serial
belongs_to :bar
end
Foo.fix {{
:bars => (1..3).of { Bar.make }
}}
Bar.fix {{
:foo => Foo.make,
:bazs => (1..3).of { Baz.make }
}}
Baz.fix {{
:bar => Bar.make,
}}
DataMapper.setup(:default, 'sqlite3::memory:')
DataMapper.auto_migrate!
foo = Foo.gen
foo.update(:current_bar => foo.bars.first)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment