Created
October 20, 2011 01:48
-
-
Save mtcmorris/1300214 to your computer and use it in GitHub Desktop.
dm belongs_to key problem
This file contains hidden or 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 '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