开发者

Datamapper validations, empty errors

开发者 https://www.devze.com 2023-04-03 05:03 出处:网络
I have a simple model with the following properties: property :title, String, :required => true, :length => 1..200

I have a simple model with the following properties:

property :title, String,
  :required => true,
  :length => 1..200

property :body, String,
  :required => true,
  :length => 1..200

When I save it (using the save method) with an title that doesn't validate, it won't save, but I get the follow object:

<DataMapper::Validations::ValidationErrors:0x00000003133e10
 @resource=#<Pun @id=nil @image="" @title="" @body="dsfsdf" @description=nil
 @published=nil @user_id=1 @round_id=nil>, @errors={}>

So the errors hash is empty. However, when it's the body property tha开发者_Python百科t's empty, the errors hash detect its problem.

Any idea on why the errors hash is empty when it involves the :title property?

Thanks


So knowtheory wrote in a comment on a blog (in 2010) that some helper methods were created to compensate for this. His examples for a User model:

User.raise_on_save_failure = true - for all user instances to blow up.

DataMapper.raise_on_save_failure = true - for EVERYTHING to blow up if it doesn’t save successfully.

Source definitions: dm-core/model.rb and dm-core/resource.rb

0

精彩评论

暂无评论...
验证码 换一张
取 消