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

Soft deletes need parentheses around proceeding query? #1592

Closed
niteraven7 opened this issue Dec 7, 2018 · 1 comment
Closed

Soft deletes need parentheses around proceeding query? #1592

niteraven7 opened this issue Dec 7, 2018 · 1 comment

Comments

@niteraven7
Copy link

If $useSoftDeletes = true in the model and you perform a query that has OR in it... the returned results are not correct because the part of the query proceeding deleted=0 is not enclosed in parentheses:

SELECT * FROM user WHERE email LIKE '%kyle%' ESCAPE '!' OR first_name LIKE '%kyle%' ESCAPE '!' OR last_name LIKE '%kyle%' ESCAPE '!' AND deleted = 0

it should be like:

SELECT * FROM user WHERE (email LIKE '%kyle%' ESCAPE '!' OR first_name LIKE '%kyle%' ESCAPE '!' OR last_name LIKE '%kyle%' ESCAPE '!') AND deleted = 0

Using query builder:

$this->like('email', $keyword)->orLike('first_name', $keyword)->orLike('last_name', $keyword)->findAll();

Alpha 3

@lonnieezell
Copy link
Member

Trying to make that happen inside of the model/query builder relationship could prove pretty darn tricky to get right. Anytime or's are used a dev has to be more careful. This functions in the same that other major frameworks I've used work. I think it's just something the developer will need to be aware of at this time.

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