Opened 16 years ago
Last modified 9 years ago
#9899 closed
GenericRelation of a childmodel can't be used in lookup — at Initial Version
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
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__ispublic=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 )
Note:
See TracTickets
for help on using tickets.