Opened 16 years ago
Closed 9 years ago
#9899 closed New feature (fixed)
GenericRelation of a childmodel can't be used in lookup
Reported by: | miracle2k | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.0 |
Severity: | Normal | Keywords: | |
Cc: | ozgurisil@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
class Feature(models.Model): object_id = models.PositiveIntegerField() content_type = models.ForeignKey(ContentType) content_object = GenericForeignKey() is_public = models.BooleanField() class Base(models.Model): pass class Child(models.Model): features = GenericRelation(Feature)
>>> Child.objects.filter(features__is_public=False).count() <class '_mysql_exceptions.OperationalError'>: (1054, "Unknown column 'app_feature.base_ptr_id' in 'where clause'")
The query that is executed:
SELECT COUNT(*) FROM `app_child` INNER JOIN `app_feature` ON (`app_child`.`feed_ptr_id` = `app_feature`.`object_id`) INNER JOIN `app_feature` T4 ON (`app_feature`.`feed_ptr_id` = T4.`id`) WHERE (`app_feature`.`feed_ptr_id` IS NOT NULL AND T4.`content_type_id` = %s )
Attachments (1)
Change History (11)
comment:1 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:2 by , 16 years ago
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
I'm reoponing for now, please confirm this is really a duplicate, because #3006 refers to GenericForeignKey, whereas this is about means GenericRelation. Using the same setup/query in a non-inheritance scenario *does* in fact work.
comment:4 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
I added a project that shows exactly how to do it. Unzip it, change the DB info, set DJANGO_SETTINGS_MODULE to 'test.settings', run syncdb, then run 'example.py'
An interesting note is that if you set the "db_column" attribute of the cabinet's o2o field to "id", the query gives the expected results, at least in the most basic of circumstances.
comment:5 by , 15 years ago
Cc: | added |
---|
comment:6 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:9 by , 12 years ago
Status: | reopened → new |
---|
comment:10 by , 9 years ago
Description: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | new → closed |
I couldn't reproduce as far back as 1.4, so I guess this has been fixed between 1.0 and then.
duplicate of #3006