Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Order the admin downloads list by its own table

Damian Legawiec757f0523763b
diff --git a/spree/api/app/controllers/spree/api/v3/admin/digital_links_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/digital_links_controller.rb
index 99a78bb562..f0583cc7ec 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/digital_links_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/digital_links_controller.rb
@@ -28,8 +28,14 @@ module Spree
Spree.api.admin_digital_link_serializer
end
+ # `digital_links` reaches links through line items, so the query
+ # carries a DISTINCT and inherits an ORDER BY on the line items'
+ # table. PostgreSQL rejects DISTINCT combined with an ORDER BY column
+ # outside the select list, so reorder by the links' own table —
+ # SQLite tolerates the inherited order, so this only surfaces on a
+ # real deployment.
def scope
- current_store.digital_links
+ current_store.digital_links.reorder("#{Spree::DigitalLink.table_name}.created_at": :desc)
end
def scope_includes