Closed pjpassa closed 7 years ago
Hi @pjpassa, thanks for the contribution! This fix makes sense but, I'm worried about potentially harmful performance if the query will return a very large number of values.
That was the reason we used query.count()
instead, to avoid potentially fetching large amount of values just to count them.
What if we order_by(field.name).distinct().count()
instead? For our simple query this should work correctly I believe.
Additionally, I would add a more specific test case, for example leaving the existing name with identical 5 names, and asserting the view returns the 1 distinct name. Later, randomizing the names (or using ID field), and asserting the max limit is reached.
Max choices used to only send data to the front end if the total number of instances of the model was less than the max choices setting.
I refactored the code so that the set was created earlier. This way the view will return data if the number of unique values is less than the max choices setting.