properly select character items based on the latest location

This commit is contained in:
jake 2020-10-03 20:19:57 -06:00
parent 0f7cbbf096
commit c067ab444a

View File

@ -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);