-
-
Save slaskis/8a151f39f7717a61984d 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 "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