diff --git a/core/MY_Model.php b/core/MY_Model.php index 8620115..3a39c76 100644 --- a/core/MY_Model.php +++ b/core/MY_Model.php @@ -51,7 +51,9 @@ class MY_Model extends CI_Model protected $after_get = array(); protected $before_delete = array(); protected $after_delete = array(); - + protected $before_replace = array(); + protected $after_replace = array(); + protected $callback_parameters = array(); /** @@ -431,7 +433,32 @@ public function delete_many($primary_values) return $result; } - + /** + * Replace data + */ + public function replace($data, $skip_validation = FALSE) + { + if ($skip_validation === FALSE) + { + $data = $this->validate($data); + } + + if ($data !== FALSE) + { + $data = $this->trigger('before_replace', $data); + + $result = $this->_database->replace($this->_table, $data); + + $this->trigger('after_replace', array($data, $result)); + + return $result; + } + else + { + return FALSE; + } + } + /** * Truncates the table */ @@ -616,6 +643,14 @@ public function table() return $this->_table; } + /** + * Getter for the primary_key + */ + public function primary_key() + { + return $this->primary_key; + } + /* -------------------------------------------------------------- * GLOBAL SCOPES * ------------------------------------------------------------ */ diff --git a/tests/MY_Model_test.php b/tests/MY_Model_test.php index 036b4d7..fe3c1fa 100644 --- a/tests/MY_Model_test.php +++ b/tests/MY_Model_test.php @@ -41,6 +41,11 @@ public function test_constructor_guesses_the_table_name() $this->assertEquals($this->model->table(), 'records'); } + public function test_get_primary_key() + { + $this->assertEquals($this->model->primary_key(), 'id'); + } + /* -------------------------------------------------------------- * CRUD INTERFACE * ------------------------------------------------------------ */