Story: a form gets input for two models (Project and associated ProjectDetail), controller tries to save form data with saveAll. Validation fails for some fields of the associated Model, even though it shouldn't (e.g. 1234 fails rule 'numeric'). After some screwing around I put debug($this->data); calls in the beforeValidate() calls of each Model, note how the 'cost' and 'revenue' fields each somehow lose their leading digit (while the date field doesn't. This field also validates properly).
Project -> beforeValidate()
$this->data = Array
(
[Project] => Array
(
[project_type_id] => 1
[name] => asdf
[cost_center] => 1234
)
[ProjectDetail] => Array
(
[cost] => 1234
[revenue] => 1234
[project_start] => 2011-07-27
)
)
ProjectDetail -> beforeValidate()
$this->data = Array
(
[ProjectDetail] => Array
(
[cost] => 234
[revenue] => 234
[project_start] => 2011-07-27
)
)
While this is annoying in itself, it doesn't seem to explain why the validation fails, since the two fields still look like numbers. So I ran the following in the beforeValidate methods too:
$cost = $this->data['ProjectDetail']['cost'];
debug('#'.$cost.'#'); //Check for obscure non-printables
debug(is_string($cost));
debug(ctype_digit($cost));
And the output:
Project -> beforeValidate()
#1234#
true
true
ProjectDetail -> beforeValidate()
#234#
true
false
So, somehow, this string lost its numeric-ness along with its leading digit. Strange. Any thoughts appreciated.
Edit: Yes, the Model saves just fine on its own.
V.S. Php 5.3.6 Cake 1.3.10 & 1.3.11