Skip to content

Instantly share code, notes, and snippets.

@hadronzoo
Created November 13, 2011 06:29
Show Gist options
  • Save hadronzoo/1361691 to your computer and use it in GitHub Desktop.
Save hadronzoo/1361691 to your computer and use it in GitHub Desktop.
Simplified test case with associations fixed
require 'dm-core'
DataMapper.setup(:default, 'sqlite::memory:')
class Project
include DataMapper::Resource
property :id, Serial
has n, :members
has n, :users, :through => :members
end
class Member
include DataMapper::Resource
belongs_to :user, :key => true
belongs_to :project, :key => true
end
class User
include DataMapper::Resource
property :id, Serial
has n, :members
has n, :projects, :through => :members
end
DataMapper.finalize
require 'dm-migrations'
DataMapper.auto_migrate!
user1 = User.new
proj = Project.new :users => [user1]
user2 = User.new
proj.users << user2 # you can also still use the << operator
puts proj.save.inspect
puts proj.users.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment