Opened 13 years ago
Closed 13 years ago
#17585 closed New feature (worksforme)
Not possible to filter authors that have books other than hardcover
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | mbertheau@…, anssi.kaariainen@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It seems that the Django ORM cannot express in one query
SELECT a.* FROM author AS a JOIN book AS b ON b.author_id = a.id WHERE b.bound <> 'hardcover' GROUP BY a.id
that is all authors that have at least one book that is not hardcover.
Both exclude(bookbound='hardcover') and filter(~Q(bookbound='hardcover')) leave only authors that had no hardcover books at all.
A field lookup 'not equal' could be provided with that meaning. Alternatively, the meaning of filter(~Q(bookbound='hardcover')) could be changed.
Change History (1)
comment:1 by , 13 years ago
Cc: | added |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
Actually, I think it can:
Or, at least I hope that is what you wanted. The .exclude() can't do what you want, it is defined to remove all authors that have any hardcovers. I admit that the above query isn't the easiest to discover. This could maybe be documented, but I don't think that is a good idea, as:
Please reopen if I am mistaken, or you disagree with my reasoning about documenting this.