Handle ambiguous column names when joining two tables #66
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ran across a problem with Idiorm (great library BTW) when joining two tables via an intermediate join table (i.e.
has_many_through()
). Here is my setup (this isn't my exact setup - i tried to simplify for illustration).Users
have manyProducts
:I have this line in my User class (using Paris):
Executing this (in Paris):
gives me a constraint violation due to ambiguous column names. The Idiorm generated query is:
This pull request contains changes to add the table name to the ambiguous column name. I added a test for this scenario, though it doesn't really make sense in the test as there are only two tables. The remaining tests all still pass.
idiorm.php
: prepend table_name when in a WHERE clausetest_queries.php
: add test joining two tables with WHERE clause