[eluser]OverZealous[/eluser] @Conerck
Thanks for the info.
I'm going to keep testing. The first change I made still has a benefit. The register_shutdown_function may not (although it has little to no performance impact).
I have determined that part of my issue looked like connection issues, but turns out to have been some bizarre DNS issue. The error message was getting swallowed because CodeIgniter hides all errors on the {db}_connect function. I'll continue testing, and provide a follow up later.
@Oblique
Once again: DMZ only checks fields that have been changed, or related rules. (There is no way for it to know if a related field has been changed or not.)
Besides, you simply are doing it wrong. You have a field marked as required, yet you aren't providing it. DataMapper is therefore telling you that you aren't providing a required field! How else should it work? Not setting a field is not setting a field. There is no way for DataMapper to know the difference.
I know I already wrote this: If you want something that to be required some of the time, but not all of the time, then set a custom _required method on the Model itself. Check the field and the model, and you can return TRUE even when empty as necessary.
Code:
class Whatever extends DataMapper {
function _required($field) {
// item1 and item2 are fields that are only check on existing objects.
if($this->exists() || !in_array($field, array('item1', 'item2'))) {
return !empty($this->{field});
}
return TRUE;
}
You can also use always_validate combined with a custom rule instead of overwriting the required rule.
The same basic concept works for _related_required — just, instead of using empty() use parent::_related_required($field)