Skip to content

Fix spy favorites showing numeric IDs instead of player/alliance names#538

Open
Copilot wants to merge 3 commits intodevelopfrom
copilot/fix-spy-favorites-display-issue
Open

Fix spy favorites showing numeric IDs instead of player/alliance names#538
Copilot wants to merge 3 commits intodevelopfrom
copilot/fix-spy-favorites-display-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

get_favoriteSpyList() was selecting player.ally_id and astro.player_id (integer FKs) into the ally and player display fields, so the favorites view rendered raw numeric IDs instead of names.

Changes

  • model/Spy_Model.phpget_favoriteSpyList()
    • Replace astro.player_idplayer.name AS player_name (player table already JOINed)
    • Replace player.ally_idally.name AS ally_name
    • Add LEFT JOIN TABLE_GAME_ALLY ally ON player.ally_id = ally.id (LEFT to preserve players without an alliance)
    • Alias user.name AS user_name to disambiguate duplicate name columns
// Before
$request = "SELECT pspy.`id`, ..., `player`.`ally_id`, `astro`.`player_id`, `player`.`status`";
$request .= " INNER JOIN " . TABLE_GAME_PLAYER . " `player` ON `astro`.`player_id` = `player`.`id`";
// No ally join — ally_id was an unresolved FK

// After
$request = "SELECT pspy.`id`, ..., `ally`.`name` AS `ally_name`, `player`.`name` AS `player_name`, `player`.`status`";
$request .= " INNER JOIN " . TABLE_GAME_PLAYER . " `player` ON `astro`.`player_id` = `player`.`id`";
$request .= " LEFT JOIN "  . TABLE_GAME_ALLY   . " `ally`   ON `player`.`ally_id`  = `ally`.`id`";

Copilot AI and others added 2 commits April 17, 2026 08:28
Copilot AI changed the title [WIP] Fix spy favorites display issue in rapports d'espionnage Fix spy favorites showing numeric IDs instead of player/alliance names Apr 17, 2026
Copilot AI requested a review from darknoon29 April 17, 2026 08:29
@darknoon29 darknoon29 marked this pull request as ready for review April 17, 2026 09:05
Copilot AI review requested due to automatic review settings April 17, 2026 09:05
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the spy favorites list so it displays player/alliance names (instead of numeric FK IDs) by selecting the proper name columns and adding the missing alliance join.

Changes:

  • Update get_favoriteSpyList() SELECT to return player.name / ally.name for display.
  • Add LEFT JOIN to the alliance table to resolve player.ally_id into an alliance name.
  • Alias user.name as user_name to avoid ambiguity among multiple name columns.

Comment thread model/Spy_Model.php
Comment on lines +44 to 51
$request = "SELECT pspy.`id`, astro.`galaxy`, astro.`system`, astro.`row`, `dateRE`, `user`.`name` AS `user_name`, `astro`.`type`, `ally`.`name` AS `ally_name`, `player`.`name` AS `player_name`, `player`.`status`";
$request .= " FROM " . TABLE_PARSEDSPY . " `pspy`";
$request .= " INNER JOIN " . TABLE_USER_BUILDING . " `astro` ON `pspy`.`astro_object_id` = `astro`.`id`";
$request .= " INNER JOIN " . TABLE_GAME_PLAYER . " `player` ON `astro`.`player_id` = `player`.`id`";
$request .= " LEFT JOIN " . TABLE_GAME_ALLY . " `ally` ON `player`.`ally_id` = `ally`.`id`";
$request .= " INNER JOIN " . TABLE_USER . " `user` ON `user`.`id` = `pspy`.`sender_id`";
$request .= " WHERE `pspy`.`sender_id`=$user_id ";
$request .= " ORDER BY " . $ordered_by;
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ORDER BY uses $ordered_by values like ally, player, and coordinates, but the query no longer has columns/aliases with those names (it selects ally_name / player_name, and coordinates are split across astro.galaxy/system/row). As a result, clicking the sort links in views/home_spy.php (sort=1..4) will produce an SQL error (Unknown column ... in order clause) or sort incorrectly. Update the $ordered_by mapping to real SQL expressions/aliases (e.g., astro.galaxy, astro.system, astro.row for coordinates; ally.name/ally_name; player.name/player_name; and astro.type for moon).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Spy favorites (espace personnel) displays IDs instead of player/alliance names

3 participants