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

Using soft deletes can lead to mysql ambiguous exception #1881

Closed
niteraven7 opened this issue Mar 27, 2019 · 3 comments
Closed

Using soft deletes can lead to mysql ambiguous exception #1881

niteraven7 opened this issue Mar 27, 2019 · 3 comments

Comments

@niteraven7
Copy link

If two tables use soft deletes and you join them together the deleted field becomes ambiguous.

For example (I believe this query is created for pagination):

SELECT COUNT(*) AS numrows
FROM recipient
INNER JOIN location ON recipient.location_id = location.id
WHERE location.business_id = 3
AND deleted = 0

deleted should be recipient.deleted to correct the issue.

version: beta1

@lonnieezell lonnieezell added this to the 4.0.0-beta.3 milestone Apr 3, 2019
@atishhamte
Copy link
Contributor

Can you provide the CodeIgniter code which generates this query?

@atishhamte
Copy link
Contributor

atishhamte commented Apr 15, 2019

@lonnieezell and @jim-parry, I have done some analysis on the code of pagination and db drivers. Found, paginate works with single model only, so there wont be chances of having join there. If we use $this->db->join, we can directly state the table name with column name to avoid ambiguous column issue.

@lonnieezell
Copy link
Member

@atishamte I don't think that's quite true about not having issues with paginate. If you would do a join with another table that has a deleted_at field, and included all fields from both tables you could run into problems, I believe.

Should be as simple as adding the table to the deletedField during the constructor, but I think we might run into issues with binding.

jim-parry added a commit that referenced this issue May 2, 2019
Using soft deletes should not return an ambiguous field message when joining tables. Closes #1881
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

3 participants