wordpress-orm
wordpress-orm copied to clipboard
Manager try to update an object if a no-managed attribute is changed
What I try to do Having on a same object some managed attributes and no-managed attributes, for example
/**
* @ORM_Column_Type smallint
* @ORM_Column_Null NOT NULL
*/
protected $userId;
/**
* @var Users
*/
protected $user;
Because there is non relation yet, I set $user after my entity loaded from the DB.
What don't work When I change a no-managed attribute and I make an make an $orm->flush(), it try to update the database. Because there is no modification on my managed attributes, nothing change on DB and it cause 'Failed to update one or more records in the database.' exception.
What it should be done The TrackedCollection should only compare the "UnkeyedValues"
Problem solved with this modifications on TrackedCollection:
l.122
'last_state' => $object->getAllUnkeyedValues()
l.194
if (isset($item['model']) && isset($item['last_state']) && $item['model']->getAllUnkeyedValues() != $item['last_state']) {
Previous correction break the "remove" function. New working correction:
l.120
$this->list[$object->getHash()] = [
'model' => $object,
'last_state' => clone $object,
'last_state_values' => $object->getAllUnkeyedValues()
];
l.195
if (isset($item['model']) && isset($item['last_state']) && $item['model']->getAllUnkeyedValues() != $item['last_state_values']) {
yield $item;
}
@Titou74 would you mind opening a pull request for this?