Skip to content

Instantly share code, notes, and snippets.

@roovo
Created June 26, 2009 09:00
Show Gist options
  • Save roovo/136380 to your computer and use it in GitHub Desktop.
Save roovo/136380 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
class User
include DataMapper::Resource
property :id, Serial
end
class Paper
include DataMapper::Resource
property :id, Serial
has n, :author_joins
has n, :authors, User, :through => :author_joins
end
class AuthorJoin
include DataMapper::Resource
property :id, Serial
property :user_id, Integer
property :paper_id, Integer
belongs_to :user
belongs_to :paper
end
DataMapper.setup(:default, "sqlite3::memory:")
User.auto_migrate!
AuthorJoin.auto_migrate!
Paper.auto_migrate!
user = User.create!
paper = Paper.create!
paper.authors << user # => NameError: Cannot find target relationship authors or author in AuthorJoin within the :default repository
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment