Skip to content

Instantly share code, notes, and snippets.

@slaskis
Created October 7, 2009 21:04
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 slaskis/8a151f39f7717a61984d to your computer and use it in GitHub Desktop.
Save slaskis/8a151f39f7717a61984d to your computer and use it in GitHub Desktop.
require "rubygems"
require "dm-core"
class User
include DataMapper::Resource
has 1, :event
property :username, String, :key => true, :unique => true
def eid=(eid)
event = Event.first_or_create( :eid => eid , :user_username => username )
end
end
class Event
include DataMapper::Resource
belongs_to :user
property :id, Serial
property :eid, String
end
DataMapper::Logger.new(STDOUT)
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/test.db")
DataMapper.auto_migrate!
u = { :username => "foo", :eid => "123" }
User.first_or_create( u ) # Works fine
User.first_or_create( u ) # Fails with: ArgumentError: condition :eid does not map to a property or relationship in User
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment