C'est une très bonne question.
Malheureusement votre chemin est seulement possible. En-dessous de la fonction ORM :: create() appelée depuis ORM :: save() en-dessous de la fonction ORM :: create().
public function create(Validation $validation = NULL)
{
if ($this->_loaded)
throw new Kohana_Exception('Cannot create :model model because it is already loaded.', array(':model' => $this->_object_name));
// Require model validation before saving
if (! $this->_valid OR $validation)
{
$this->check($validation);
}
$data = array();
foreach ($this->_changed as $column)
{
// Generate list of column => values
$data[$column] = $this->_object[$column];
}
if (is_array($this->_created_column))
{
// Fill the created column
$column = $this->_created_column['column'];
$format = $this->_created_column['format'];
$data[$column] = $this->_object[$column] = ($format === TRUE) ? time() : date($format);
}
$result = DB::insert($this->_table_name)
->columns(array_keys($data))
->values(array_values($data))
->execute($this->_db);
if (! array_key_exists($this->_primary_key, $data))
{
// Load the insert id as the primary key if it was left out
$this->_object[$this->_primary_key] = $this->_primary_key_value = $result[0];
}
else
{
$this->_primary_key_value = $this->_object[$this->_primary_key];
}
// Object is now loaded and saved
$this->_loaded = $this->_saved = TRUE;
// All changes have been saved
$this->_changed = array();
$this->_original_values = $this->_object;
return $this;
}
Comme vous pouvez le voir, il n'y a pas de valeurs ... defaut
Merci! Peut-être que c'est trop pédant, mais y a-t-il une raison pour qu'il soit préférable d'utiliser '_loaded' plutôt que 'loaded()'? Ou juste une question de préférence d'ordre de code? – Jordan
@jord: regarde les premières lignes de la méthode 'Kohana_ORM :: __ call()'. Il y a juste un travail inutile (dans votre cas). – zerkms
Ah je vois. Merci! – Jordan