codeigniter-base-model
codeigniter-base-model copied to clipboard
Delete with where?
In my model, I'm writing a new method that calls several model methods inside a transaction.
The queries all deal with deleting data.
I am starting off with a call to the same model, deleting a row where the ID matches the input variable and a flag is set to 1
So, the first bit is easy, $this->delete($job_id) but I want to combine that with a WHERE statement, so I tried the following, based on the bit of documentation in the readme, $this->delete($job_id)->get_by('archived', 1); - this failed miserably with the following error
Fatal error: Call to a member function get_by() on a non-object
FYI, here is the code from the readme I'm referring too. I know it's about soft deletes, but I assume it should work with normal deletes?
=> $this->book_model->only_deleted()->get_by('user_id', 1);
-> SELECT * FROM books WHERE user_id = 1 AND deleted = 1
So, how do I do a delete with a where statement?
You could use the "delete_by" method as follows:
$this->book_model->delete_by(
array(
'id' => $job_id,
'archived' => 1
)
);