The fetch loop reused a single $tmpobj declared before the loop and reset only $tmpobj->id before each fetch. Object classes whose fetch() does not clear every property left stale data from previous rows, and the shallow 'clone $tmpobj' kept nested object references (thirdparty, extrafields, ...) pointing at the last fetched row. Instantiate a fresh $tmpobj per row and append it directly so each returned entry is fully independent. Signed-off-by: Dolicraft <contact@dolicraft.com> Co-authored-by: Dolicraft <contact@dolicraft.com>
This commit is contained in:
parent
20943def41
commit
6df10d2b77
1 changed files with 3 additions and 3 deletions
|
|
@ -1050,11 +1050,11 @@ class Categorie extends CommonObject
|
|||
if ($onlyids) {
|
||||
$objs[] = $rec['fk_object'];
|
||||
} else {
|
||||
$tmpobj->id = 0;
|
||||
$tmpobj->fetch($rec['fk_object']); // The fetch will erase $tmpobj->id only if it succeed.
|
||||
$tmpobj = new $classnameforobj($this->db);
|
||||
$tmpobj->fetch($rec['fk_object']); // The fetch will set $tmpobj->id only if it succeed.
|
||||
// @phpstan-ignore-next-line
|
||||
if ($tmpobj->id > 0) { // Failing fetch may happen for example when a category supplier was set and third party was moved as customer only. The object supplier can't be loaded.
|
||||
$objs[] = clone $tmpobj;
|
||||
$objs[] = $tmpobj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue