Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions core/MY_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
* ------------------------------------------------------------ */
Expand Down
5 changes: 5 additions & 0 deletions tests/MY_Model_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
* ------------------------------------------------------------ */
Expand Down