Created
August 28, 2009 16:18
-
-
Save robholland/177077 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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