Opened 6 years ago

Closed 6 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: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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.

Change History (1)

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to fixed
  • Status changed from new to closed

It appears that this problem has been fixed - it was probably a result of the m2m refactor.

Note: See TracTickets for help on using tickets.
Back to Top