wordpress-orm icon indicating copy to clipboard operation
wordpress-orm copied to clipboard

Manager try to update an object if a no-managed attribute is changed

Open Titou74 opened this issue 3 years ago • 3 comments

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"

Titou74 avatar Jul 20 '21 17:07 Titou74

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']) {

Titou74 avatar Jul 20 '21 17:07 Titou74

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 avatar Jul 23 '21 07:07 Titou74

@Titou74 would you mind opening a pull request for this?

rjjakes avatar Oct 27 '22 14:10 rjjakes