cakephp/cakephp — pull request #778 by mrmorris (2012-08-16 13:44:52+00:00)
Title: 2.3/validation not clearing

Hello! I stumbled across an issue with validation while migrating from Cake 1.3 to 2.3.

This is my first submission to the Cake project so apologies if I break protocol here, just let me know and I can clean things up.

It looks like a `Model->create()` will not clear all validation data. Per the test case provided in my commit:
>
- Given two fields
- And both cannot be empty if provided in the data
- And one is required (must always be provided) while the other is not required
- When we save empty data for both fields
- Then both fields should fail validation

This is all well and dandy, however if we attempt to flush the model with a call to `create()` and then re-submit some data, this time:
>
- Given the same conditions as above
- When we save valid data for field 1 and do not provide field 2
- Then field 1 should validate and field 2, being not present, should not even have to pass validation

This fails, which can be a problem when iterating through data to save and relying on `Model->create()` calls to flush things out before each new save.

Seems like `CakeValidationRule` objects were not being re-initialized when initializing the model with a call to `create()`, so that their `$_valid` property would remain set.

To remedy all this I created a fresh `ModelValidator` instance when calling `Model->create()`. Perhaps there is an alternative way to go about this, which I'm curious to hear about! However, this solution has worked for us for the time being and I wanted to pass it on.