Changes between Initial Version and Version 1 of Ticket #33568
- Timestamp:
- Mar 8, 2022, 9:24:37 AM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #33568 – Description
initial v1 1 1 This query: 2 {{{ #!python 2 3 Shop.objects\ 3 4 .filter(Publish = True, Available = True)\ … … 5 6 .filter(product_count__gt=1)\ 6 7 .order_by('?').values('ID')[:12] 7 8 }}} 8 9 and ORM generate this SQL: 10 {{{ #!sql 9 11 SELECT "nakhll_market_shop"."ID" FROM "nakhll_market_shop" LEFT OUTER JOIN "nakhll_market_product" ON ("nakhll_market_shop"."ID" = "nakhll_market_product"."FK_Shop_id") WHERE ("nakhll_market_shop"."Available" AND "nakhll_market_shop"."Publish") GROUP BY "nakhll_market_shop"."ID", RANDOM() HAVING COUNT("nakhll_market_product"."ID") > 1 ORDER BY RANDOM() ASC LIMIT 12 10 12 }}} 11 13 but it does not return any shop, 12 14 the correct SQL query is: 15 {{{ #!sql 13 16 SELECT "nakhll_market_shop"."ID" FROM "nakhll_market_shop" LEFT OUTER JOIN "nakhll_market_product" ON ("nakhll_market_shop"."ID" = "nakhll_market_product"."FK_Shop_id") WHERE ("nakhll_market_shop"."Available" AND "nakhll_market_shop"."Publish") GROUP BY "nakhll_market_shop"."ID" HAVING COUNT("nakhll_market_product"."ID") > 1 ORDER BY RANDOM() ASC LIMIT 12 14 17 }}}