From dcd4f6a3b471280993134a6b12abf0969983b735 Mon Sep 17 00:00:00 2001 From: michail1982 Date: Mon, 19 Nov 2012 10:48:42 +0200 Subject: [PATCH 1/3] Update core/MY_Model.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add getter for the primary_key --- core/MY_Model.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/MY_Model.php b/core/MY_Model.php index 8620115..5a16b7e 100644 --- a/core/MY_Model.php +++ b/core/MY_Model.php @@ -616,6 +616,14 @@ public function table() return $this->_table; } + /** + * Getter for the primary_key + */ + public function primary_key() + { + return $this->primary_key; + } + /* -------------------------------------------------------------- * GLOBAL SCOPES * ------------------------------------------------------------ */ From 12a4e09de9c2f2069ac01b58b62c93f5dc927caf Mon Sep 17 00:00:00 2001 From: michail1982 Date: Mon, 19 Nov 2012 11:19:23 +0200 Subject: [PATCH 2/3] Update tests/MY_Model_test.php test_get_primary_key() --- tests/MY_Model_test.php | 5 +++++ 1 file changed, 5 insertions(+) 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 * ------------------------------------------------------------ */ From 81b792f73e565435a099c80b9d9608a59329e1ee Mon Sep 17 00:00:00 2001 From: michail1982 Date: Tue, 2 Jun 2015 14:07:14 +0300 Subject: [PATCH 3/3] Update MY_Model.php --- core/MY_Model.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/core/MY_Model.php b/core/MY_Model.php index 5a16b7e..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 */