From b55c8373d387819fd1796e72c6a17aff4ae8a641 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Tue, 16 Jul 2024 19:00:48 +0200 Subject: [PATCH] Fix item order in get_parents_details --- ...6ede68b890b8bf3208b55b51433ec92b4e7a452929a81945.json} | 4 ++-- src/manage/item.rs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) rename .sqlx/{query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json => query-9286b6ee0c08b8446ede68b890b8bf3208b55b51433ec92b4e7a452929a81945.json} (74%) diff --git a/.sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json b/.sqlx/query-9286b6ee0c08b8446ede68b890b8bf3208b55b51433ec92b4e7a452929a81945.json similarity index 74% rename from .sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json rename to .sqlx/query-9286b6ee0c08b8446ede68b890b8bf3208b55b51433ec92b4e7a452929a81945.json index 6ce9417..c12a41f 100644 --- a/.sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json +++ b/.sqlx/query-9286b6ee0c08b8446ede68b890b8bf3208b55b51433ec92b4e7a452929a81945.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT * FROM items WHERE id = ANY (SELECT unnest(parents) FROM item_tree WHERE id = $1)", + "query": "SELECT items.*\n FROM items\n INNER JOIN\n unnest((SELECT parents FROM item_tree WHERE id = $1))\n WITH ORDINALITY AS parents(id, n)\n ON items.id = parents.id\n ORDER BY parents.n;", "describe": { "columns": [ { @@ -60,5 +60,5 @@ false ] }, - "hash": "e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d" + "hash": "9286b6ee0c08b8446ede68b890b8bf3208b55b51433ec92b4e7a452929a81945" } diff --git a/src/manage/item.rs b/src/manage/item.rs index 74fe901..7bb35a2 100644 --- a/src/manage/item.rs +++ b/src/manage/item.rs @@ -122,7 +122,13 @@ pub async fn get_all_parents(pool: &PgPool) -> Result>, pub async fn get_parents_details(pool: &PgPool, id: Uuid) -> Result, sqlx::Error> { query_as!( Item, - "SELECT * FROM items WHERE id = ANY (SELECT unnest(parents) FROM item_tree WHERE id = $1)", + "SELECT items.* + FROM items + INNER JOIN + unnest((SELECT parents FROM item_tree WHERE id = $1)) + WITH ORDINALITY AS parents(id, n) + ON items.id = parents.id + ORDER BY parents.n;", id ) .fetch_all(pool)