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

fixForeignRecord crash on deleted Records #5

Open
sunkan opened this issue Dec 6, 2018 · 3 comments
Open

fixForeignRecord crash on deleted Records #5

sunkan opened this issue Dec 6, 2018 · 3 comments

Comments

@sunkan
Copy link
Contributor

sunkan commented Dec 6, 2018

This code will crash with TokenRow::$account_id is immutable after Row is deleted

$account = $mapper->fetchRecord(1, ['tokens']);

$token = $account->tokens->getOneBy(['type' => 'test']);

if (isValid($token)) {
    $atlas->delete($token);
}

$account->modified = date('c');
$atlas->update($account);

Is this the intended behavior?

Ps.
I found out will writing this issue that I can use detachOneBy instead of getOneBy but that's not always what you want.

Ps 2.
Also found the detachDeleted method.

We should probably update the documentation with a not about this behavior

@far-blue
Copy link
Contributor

far-blue commented Apr 4, 2019

I think I'm getting the same issue with a different case.

I have a record A with a oneToOne relationship with record B.

If I fetch an instance of A and include the 'with' for record B and then later try to delete the instance of A, it appears to mark the instance of record B as deleted and then attempt to update the foreign key value from A onto the deleted instance of B.

I'm using non-primary key linking in the relationship between A and B using a uuid field.

I get the error B::$uuid is immutable after Row is deleted.

@far-blue
Copy link
Contributor

far-blue commented Apr 4, 2019

Just to clarify, I'm using setDelete() and persist() rather then delete() on the instance of A.

@pmjones
Copy link
Contributor

pmjones commented May 29, 2021

@sunkan

  1. Yes, immutable-after-deletion is the intended behavior, though I get why it was surprising and unexpected.
  2. Looking this over, it seems like detachOneBy() is the right thing to do in this particular case, followed by delete(). E.g., $token = $account->tokens->detachOneBy(...); $atlas->delete($token);.
  3. Yes, better documentation would help; my apologies for not making it more obvious.

@far-blue

Deletion of one should not cause Atlas to infer the deletion of the other. I have tried replicating that behavior but have been unsuccessful. Are you still seeing the problem (yes, two years later, I know, sorry) ?

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

3 participants