Opened 15 years ago
Closed 15 years ago
#12169 closed (fixed)
QuerySet method count() on models with a manytomanyfield not working in the latest trunk
Reported by: | shilin | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a model like this:
class Thread(models.Model): group = models.ForeignKey(Group) creator = models.ForeignKey(Profile) categories = models.ManyToManyField('object.Category')
you can see that it has a manytomanyfield to the model Category in the application named object
due to the way that I'm not directly importing the model Category but use a string instead,
the following query will return a error
Thread.objects.filter(categories__in = category_list).count()
no such column: group_thread_categories.object.category_id
as in the database level, the ORM generates a query like this
'SELECT COUNT(*) FROM "group_thread" INNER JOIN "group_thread_categories" WHERE ("group_thread_categories"."object.category_id" IN (?))'
this bug doesn't appear in revision 9800 because i just checked out svn today and my code starts to break.
Note:
See TracTickets
for help on using tickets.
It appears that this problem has been fixed - it was probably a result of the m2m refactor.