# Validation fails but objects seems to have the values

**URL:** <https://www.ruby-forum.com/t/validation-fails-but-objects-seems-to-have-the-values/175818>\
**Category:** Rails\
**Created:** [September 20, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/validation-fails-but-objects-seems-to-have-the-values/175818 "2009-09-20T17:17:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PanosJee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@PanosJee](https://www.ruby-forum.com/u/PanosJee)\
**Post date:** [September 20, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/validation-fails-but-objects-seems-to-have-the-values/175818/1 "2009-09-20T17:17:14Z")

</div>

Hello everyone i am trying to save a nested model but it will always  
fail because 2 fields are missing  
I tried to examine what happens so i print the object to yaml, here s  
what i got:

- &id001 !ruby/object:Contract  
attributes:  
price:  
room\_id:  
start\_date: 15/09/2009  
created\_at:  
is\_consecutive: false  
same\_sex: false  
comments:  
updated\_at:  
has\_keys: false  
touched\_by:  
amount\_to\_keep: 0  
house\_id:  
user\_id: 0  
paid\_percent: 0.0  
has\_signed: false  
shared: true  
house\_rating: 0  
deposit\_returned: false  
service\_rating: 0  
booking\_date:  
end\_date: 14/02/2010  
active: false  
attributes\_cache:  
start\_date:  
end\_date:  
changed\_attributes: {}

The only fields that i am checking for presence are the start\_date and  
end\_date as you can see in the yaml they have a value but then  
validation fails.

Thanx a lot for your time

---

<div class="post-metadata">

**Author:** ![PanosJee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@PanosJee](https://www.ruby-forum.com/u/PanosJee)\
**Post date:** [September 23, 2009, 2:46am UTC](https://www.ruby-forum.com/t/validation-fails-but-objects-seems-to-have-the-values/175818/2 "2009-09-23T02:46:23Z")

</div>

Could it be that the DB itself ha constraints you’re not thinking of?  
For example, not nullable fields that are getting a null.

Are you using a bang method (save! or create!)? If you’re not, change  
it at least for testing, it will most likely make the app. raise an  
error and might be very informative. If you are using your\_object.save  
it will only return true/false and finding out what is wrong is going  
to be more complicated.

Posting some code might also help others to help you.

---

<div class="post-metadata">

**Author:** ![PanosJee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@PanosJee](https://www.ruby-forum.com/u/PanosJee)\
**Post date:** [September 23, 2009, 8:53am UTC](https://www.ruby-forum.com/t/validation-fails-but-objects-seems-to-have-the-values/175818/3 "2009-09-23T08:53:33Z")

</div>

I found the errors 2 days ago, it is quite strange.  
I was saving the dates with this format dd/mm/yy  
That would work for parent model but not the nested! I had to change  
the date to yy-mm-dd for the nested object and it just worked!
