Skip to content

Instantly share code, notes, and snippets.

@robholland
Created August 28, 2009 16:18
Show Gist options
  • Save robholland/177077 to your computer and use it in GitHub Desktop.
Save robholland/177077 to your computer and use it in GitHub Desktop.
require 'dm-core'
class A
include DataMapper::Resource
property :id, Serial
has n, :bs, :through => Resource
end
class B
include DataMapper::Resource
property :id, Serial
has n, :as, :through => Resource
end
DataMapper.setup(:default, "sqlite3::memory:")
DataMapper.auto_migrate!
a1 = A.create
a2 = A.create
a3 = A.create
b1 = B.create
b2 = B.create
b3 = B.create
a2.bs = [b1, b2, b3]
a2.save
A.all.each do |a|
puts [a.id, a.bs].inspect
end
# Output:
# » ruby -rubygems dm_test.rb
# [1, [#<B @id=1>]]
# [2, [#<B @id=2>]]
# [3, [#<B @id=3>]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment