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

Allow overriding association's cascade #11549

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

malarzm
Copy link
Member

@malarzm malarzm commented Jul 11, 2024

We were badly bitten by cascade set on an association we did not expect it to have. The association is dynamically mapped using a loadClassMetadata event by a vendor with no way of hooking into it. As we're really careful with persisting stuff I'd like to have an option to remove vendor's cascade and instead take care of it within our codebase.

Additionally I've listed what can actually be overridden as I was surprised it's that limited :)

Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of weird that everything can be overridden but not cascade. I assume this was forgotten to be implemented, but I'm not sure if this had a reason.

@@ -870,13 +870,23 @@ public function testAssociationOverrideKeepsDeclaringClass(): void
{
$cm = new ClassMetadata(Directory::class);
$cm->mapManyToOne(['fieldName' => 'parentDirectory', 'targetEntity' => Directory::class, 'cascade' => ['remove'], 'declared' => Directory::class]);
$cm->setAssociationOverride('parentDirectory', ['cascade' => '']);
$cm->setAssociationOverride('parentDirectory', ['cascade' => ['remove']]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change in the test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously cascade was ignored, now it's leading to an error as it's supposed to be an array of strings. I reckon this test was originally done to pass something and see if nothing (declaring class) breaks

@malarzm
Copy link
Member Author

malarzm commented Jul 16, 2024

I assume this was forgotten to be implemented, but I'm not sure if this had a reason.

I gave it some thought and couldn't think of any reason this would be omitted on purpose. My guess is that nobody needed it as overriding association is not very common: people either configure things themselves or roll with vendors. I don't like vendors shooting me in the foot :D

Copy link
Contributor

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.

@github-actions github-actions bot added the Stale label Oct 17, 2024
@malarzm
Copy link
Member Author

malarzm commented Oct 17, 2024

@SenseException can we treat this as bugfix and still merge to 3.x?

@github-actions github-actions bot removed the Stale label Oct 18, 2024
@SenseException
Copy link
Member

I guess being the only option that can't be overridden could be interpreted as a bug. I guess this is a situation that can be argued about. 😁

I would give an okay to handle this as a bugfix.

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't have to change any tests, so yeah, it should be fine 👍

@greg0ire greg0ire merged commit 05f5486 into 3.3.x Oct 22, 2024
64 checks passed
@greg0ire greg0ire added the Bug label Oct 22, 2024
@greg0ire greg0ire added this to the 3.3.1 milestone Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants