Fix item order in get_parents_details

This commit is contained in:
Simon Bruder 2024-07-16 19:00:48 +02:00
parent 125627d7d2
commit b55c8373d3
Signed by: simon
GPG key ID: 347FF8699CDA0776
2 changed files with 9 additions and 3 deletions

View file

@ -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"
}

View file

@ -122,7 +122,13 @@ pub async fn get_all_parents(pool: &PgPool) -> Result<HashMap<Uuid, Vec<Uuid>>,
pub async fn get_parents_details(pool: &PgPool, id: Uuid) -> Result<Vec<Item>, 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)