Skip to content

fix(history): set correct tableName for archived rows in all()#3377

Open
zoic21 wants to merge 1 commit into
developfrom
fix/history-all-tablename
Open

fix(history): set correct tableName for archived rows in all()#3377
zoic21 wants to merge 1 commit into
developfrom
fix/history-all-tablename

Conversation

@zoic21

@zoic21 zoic21 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Problème

history::all() combine les tables history et historyArch via UNION ALL, puis hydrate toutes les lignes en objets history (PDO::FETCH_CLASS). La requête ne transporte pas la table d'origine, et la classe a protected $_tableName = 'history' par défaut. Résultat : les lignes provenant de historyArch renvoient quand même _tableName = 'history'.

C'est gênant car getTableName() cible la table en écriture (REPLACE INTO ... getTableName() dans save(), idem remove()). Éditer/supprimer un point archivé récupéré via all() visait donc history au lieu de historyArch.

Correctif

On fait porter la table source à chaque ligne via une colonne littérale _tableName, que PDO mappe sur la propriété protégée $_tableName (comme cmd_id/value/datetime, également protected) :

  • sous-requêtes internes : SELECT *, 'history' as _tableName from history ... / SELECT *, 'historyArch' as _tableName from historyArch ... ;
  • la colonne n'est sélectionnée dans le SELECT externe que dans le cas non groupé — en mode groupé les lignes des deux tables sont agrégées ensemble (table source sans signification, objets non éditables) ;
  • même traitement dans le bloc _addFirstPreviousValue (toujours non groupé).

Notes

  • Aucune migration ni changement de schéma : 'history'/'historyArch' sont des littéraux SQL.
  • Le marqueur ajouté aux sous-requêtes est inoffensif en mode groupé (colonne ignorée par les SELECT agrégés).
  • UNION ALL reste valide : les deux sous-requêtes reçoivent la même colonne supplémentaire.

Closes #3097


Generated by Claude Code

history::all() unions the history and historyArch tables and hydrates
every row as a history object, so rows coming from the archive kept the
default _tableName 'history'. Carry the source table as a literal column
in the (non-grouped) query so PDO populates _tableName correctly,
ensuring later save()/remove() target the right table.

Closes #3097
@zoic21 zoic21 requested review from Mips2648 and Salvialf June 15, 2026 09:47
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] class history mauvais Tablename

1 participant