Skip to content

Instantly share code, notes, and snippets.

@mtcmorris
Created October 20, 2011 01:48
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 mtcmorris/1300214 to your computer and use it in GitHub Desktop.
Save mtcmorris/1300214 to your computer and use it in GitHub Desktop.
dm belongs_to key problem
require 'dm-core'
require 'dm-migrations'
require 'dm-validations'
DataMapper.setup :default, "sqlite::memory"
class User
include DataMapper::Resource
property :id, Serial
has 1, :image
end
class Image
include DataMapper::Resource
belongs_to :user, key: true
end
DataMapper.finalize
DataMapper.auto_migrate!
image = Image.new user: User.new
image.valid? # false - User must not be blank
image.save # true - works as expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment