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

Open
wants to merge 1 commit into
base: 3.3.x
Choose a base branch
from

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

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

Successfully merging this pull request may close these issues.

None yet

2 participants