Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete with where? #234

Open
paulcanning opened this issue Apr 12, 2017 · 1 comment
Open

Delete with where? #234

paulcanning opened this issue Apr 12, 2017 · 1 comment

Comments

@paulcanning
Copy link

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?

@charleyskira
Copy link

You could use the "delete_by" method as follows:

$this->book_model->delete_by(
    array(
        'id' => $job_id, 
        'archived' => 1
    )
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants