[eluser]bhogg[/eluser]
Sure, here is the part that reloads the data, the rest just checks to make sure it's a valid id. Note that readonly_defn is an empty array.
Code:
$CI =& get_instance();
$db = $CI->db;
// Build the select portion of the query, and join readonly values
$select = self::TABLE.".*";
$db->from(self::TABLE);
foreach ($this->_readonly_defn as $field => $arr)
{
foreach ($arr as $value => $condition)
{
$select .= ", {$value} as {$field}";
$db->join(substr($value, 0, strpos($value, ".")), $condition, 'left');
}
}
$db->select($select);
// Get only the applicable row
$db->where(array(self::TABLE.'.id' => $id));
// Get the results and update our internal data
$query = $db->get();
if ($query->num_rows())
{
$this->_data = $query->row_array();
foreach ($this->_readonly_defn as $field => $arr)
{
$this->_readonly[$field] = $this->_data[$field];
unset($this->_data[$field]);
}
}