I'm using Datamapper v1.8.2 with Codeigniter v2.1.2 and have a "get" rule that doesn't seem to run on fields with NULL
values. Here's the model:
class Page extends Datamapper {
public $validation = array(
'name' => array(
'rules' => array('required'),
'get_rules' => array('get_page_name')
)
);
function _get_page_name($field)
{
$this->$field = 'TESTING '.$this->id;
}
}
Example code:
$page = new Page();
foreach ($page->get() as $p) echo $p->name;
When the table field name
has any non-null value including an empty string it works fine outputting something like TESTING 358
, but when the value is NULL
(which is the default value for this field), it outputs nothing. There is no difference using get_iterated()
.
I guess I could work around this by changing the default value, but I'm wondering if I'm doing something wrong or missed something in the documentation, or maybe it's a bug? Does anyone know what the issue is?
Also, if someone could point me to the proper thread in the CI forums for Datamapper 1.8.2 support that would be great, I'm trying to find it and getting lost in a maze of links to threads for old versions of DM.
You need to add the allow_null
to the get_rules
array to make this work. I'm not sure about the intent of the creator but this is how get_rules are implemented (however i don't see it mentioned in the docs).