#33775: subquery must return only one column
-------------------------------------+-------------------------------------
Reporter: Mohammad | Owner: nobody
Ali Mehdizadeh |
Type: Bug | Status: new
Component: Database | Version: 3.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have two tables:
{{{
class Product(models.Model):
name = models.CharField(max_length=127)
category = models.ForeignKey('Category', on_delete=models.CASCADE,
related_name='products')
class Category(models.Model):
name = models.CharField(max_length=127)
parent = models.ForeignKey('self', on_delete=models.CASCADE,
null=True, blank=True, related_name='children')
}}}
I want to get all categories that have at least one product-related or
their children to have at least one product.
So I have a query like:
{{{
Category.objects.all().annotate(product_count_parent=Count('products')).filter(Q(product_count_parent__gt=0)
|
Q(children__id__in=Category.objects.filter(children=None).annotate(product_count=Count('products')).filter(product_count__gt=0)))
}}}
I have gotten this error
{{{
ProgrammingError: subquery must return only one column
LINE 1: ... GROUP BY "nakhll_market_category"."id", T3."id", (SELECT U0...
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33775>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018148824165-4d9e1a7a-5e17-45fa-acd1-8c7da3006e85-000000%40eu-central-1.amazonses.com.