﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33775	subquery must return only one column	Mohammad Ali Mehdizadeh	nobody	"
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...
}}}"	Bug	closed	Database layer (models, ORM)	3.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
