Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

lazy loaded porperties cause .save failure even if you don't touch that property. #3

Open
MarcWeber opened this issue Nov 11, 2012 · 0 comments

Comments

@MarcWeber
Copy link

sample code derived from http://datamapper.org/docs/create_and_destroy.html,
When you run it the second time you'll get the error:

/pr/tasks/ruby/datamapper/dm/dm-core/lib/dm-core/property.rb:712:in `assert_valid_value': Invalid value nil for property :body (DataMapper::Property::Text) on model Post (DataMapper::Property::InvalidValueError)

CODE:

# encoding: UTF-8
require 'dm-core'

$DATA_MAPPER_MYSQL_CONNECTION = 'mysql://root:mysqlpage@localhost/datamapper'

# If you want the logs displayed you have to do this before the call to setup
DataMapper::Logger.new($stdout, :debug)

DataMapper.setup(:default, $DATA_MAPPER_MYSQL_CONNECTION )

# by default all fields are required
DataMapper::Property.required(true)
DataMapper::Property::String.length(120)
DataMapper::Property::Boolean.allow_nil(false)
DataMapper::Model.raise_on_save_failure = true

class Post
  include DataMapper::Resource

  property :id, Serial
  property :title, String
  property :body, Text

end

DataMapper.finalize

require  'dm-migrations'
DataMapper.auto_upgrade!

if Post.first
  puts "phase2 editing post"
  post = Post.first
  post.title = "dummy"
  # this causes an exception because body porperty is nil because its loaded lazily !?
  post.save
else
  puts "creating post, rerun script!"
  post = Post.create({
    :title =>  "My first DataMapper post",
    :body => "A lot of text ...",
  })
end

# repository(:default).adapter.execute('COMMIT')

This causes the feeling that the mysql backend (and maybe all?) are still kind of unstable.

Tell me if I should file this bug against a different github repo.. maybe its not related to mysql at all.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant