Changes between Initial Version and Version 1 of Ticket #33568


Ignore:
Timestamp:
Mar 8, 2022, 9:24:37 AM (3 years ago)
Author:
Tim Graham
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33568 – Description

    initial v1  
    11This query:
     2{{{ #!python
    23    Shop.objects\
    34    .filter(Publish = True, Available = True)\
     
    56    .filter(product_count__gt=1)\
    67    .order_by('?').values('ID')[:12]
    7 
     8}}}
    89and ORM generate this SQL:
     10{{{ #!sql
    911SELECT "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}}}
    1113but it does not return any shop,
    1214the correct SQL query is:
     15{{{ #!sql
    1316SELECT "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}}}
Back to Top