group by field from related model instead of field from original model #360
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.
This is a:
master
dev/
branchdev/
branchDescription & motivation
The
cardinality_equality
test is grouping by the wrong field in the related model. Rather than using the field specified as a parameter to the test, it's using the field from the original model. This means if the field doesn't exist on the related model, you'll get a "column does not exist" error when running the test.For example consider two models: car and make.
Each car has a make (eg: Ford, Hyundai etc). Each make is represented at least once in our set of cars (ie: there's at least one Ford, one Hyundai etc).
Given this, I would expect the cardinality of the
make_id
column in thecar
model to equal the cardinality of theid
column in themake
model, such that the following test would pass:Instead you'll get an error when the test runs along the lines of:
This is because the
GROUP BY
statement that's grouping the related model (ie: the model specified by theto
parameter in the test) is referencing the column that's being tested, rather than the column specified as thefield
parameter.The fix here was simply to use the
field
parameter in theGROUP BY
for the related model.Checklist
I don't think any README or test updates are necessary. Unsure if I need to add an entry to the CHANGELOG.md. Please advise if there's something required here.