Validation check, empty errors

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 a heading that is not checked, it will not be saved, but I get the following object:

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

Therefore, the error hash is empty. However, when this body property is empty, the error hash detects its problem.

Any idea on why the error hash is empty when it includes the title property:

thanks

+6
source share
1 answer

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

User.raise_on_save_failure = true - explode for all user instances.

DataMapper.raise_on_save_failure = true - for EVERYTHING to explode if it doesn't save successfully.

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

0
source

Source: https://habr.com/ru/post/896632/


All Articles