From c067ab444a2938cc4212eb2ebfa43eda8fd8ae26 Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 3 Oct 2020 20:19:57 -0600 Subject: [PATCH] properly select character items based on the latest location --- src/entity/gateway/postgres/postgres.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index c400da4..3ae3f2c 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -322,6 +322,13 @@ impl EntityGateway for PostgresGateway { join item on item.id = item_location.item where cast (location -> 'Inventory' ->> 'character_id' as integer) = $1 or cast (location -> 'Bank' ->> 'character_id' as integer) = $1"#; + let q = r#"select * from ( + select distinct on (item_location.item) item.id, item_location.location, item.item + from item_location join item on item.id = item_location.item + order by item_location.item, item_location.created_at desc + ) as i + where cast (location -> 'Inventory' ->> 'character_id' as integer) = 2 + or cast (location -> 'Bank' ->> 'character_id' as integer) = 2"#; let items = sqlx::query_as::<_, PgItemWithLocation>(q) .bind(char.id.0) .fetch(&self.pool);