fix(history): set correct tableName for archived rows in all()#3377
Open
zoic21 wants to merge 1 commit into
Open
fix(history): set correct tableName for archived rows in all()#3377zoic21 wants to merge 1 commit into
zoic21 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problème
history::all()combine les tableshistoryethistoryArchviaUNION ALL, puis hydrate toutes les lignes en objetshistory(PDO::FETCH_CLASS). La requête ne transporte pas la table d'origine, et la classe aprotected $_tableName = 'history'par défaut. Résultat : les lignes provenant dehistoryArchrenvoient quand même_tableName = 'history'.C'est gênant car
getTableName()cible la table en écriture (REPLACE INTO ... getTableName()danssave(), idemremove()). Éditer/supprimer un point archivé récupéré viaall()visait donchistoryau lieu dehistoryArch.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(commecmd_id/value/datetime, égalementprotected) :SELECT *, 'history' as _tableName from history .../SELECT *, 'historyArch' as _tableName from historyArch ...;SELECTexterne 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) ;_addFirstPreviousValue(toujours non groupé).Notes
'history'/'historyArch'sont des littéraux SQL.SELECTagrégés).UNION ALLreste valide : les deux sous-requêtes reçoivent la même colonne supplémentaire.Closes #3097
Generated by Claude Code