Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Titou74 opened this issue Jul 20, 2021 · 3 comments
Open

Comments

@Titou74
Copy link

Titou74 commented Jul 20, 2021

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 Titou74 changed the title Manager try to update an object if a no-ORM attribute is changed Manager try to update an object if a no-managed attribute is changed Jul 20, 2021
@Titou74
Copy link
Author

Titou74 commented Jul 20, 2021

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
Copy link
Author

Titou74 commented Jul 23, 2021

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;
      }

@rjjakes
Copy link
Owner

rjjakes commented Oct 27, 2022

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

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

No branches or pull requests

2 participants