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

Fix schema creation for self referencing many to many association #537

Conversation

X-Coder264
Copy link
Contributor

@X-Coder264 X-Coder264 commented Feb 13, 2023

Subject

I am targeting this branch, because it's a bug fix.

We've tried to upgrade from 1.7 to 1.9 but our CI was failing with the following exception:

Doctrine\DBAL\Schema\Exception\TableDoesNotExist: There is no table with name "foo" in the schema.
/app/vendor/doctrine/dbal/src/Schema/Exception/TableDoesNotExist.php:16
/app/vendor/doctrine/dbal/src/Schema/SchemaException.php:68
/app/vendor/doctrine/dbal/src/Schema/Schema.php:188
/app/vendor/sonata-project/entity-audit-bundle/src/EventListener/CreateSchemaListener.php:102

Further debugging showed that the issue was introduced in #509 as the case of a self referencing many to many association which uses class table inheritance was not taken into consideration in the create schema listener class so it currently tries to create the revision/audit table for the related table which does not yet exist at that point. The fix was to execute that logic (if we run into that case) in the post schema generation event instead where we are sure that all schema tables are created so we can then safely create the revision table for them.

Changelog

### Fixed
- Schema creation for self referencing many to many association with class table inheritance

@X-Coder264 X-Coder264 force-pushed the fix-self-referencing-many-to-many branch from 537b926 to 1f90ab3 Compare February 13, 2023 00:10
@VincentLanglet
Copy link
Member

Does it solve #522 or is it a different issue ?

@X-Coder264
Copy link
Contributor Author

#522 seems to be about a NotNullConstraintViolationException exception that gets thrown while the audit records are being recorded, while this issue is about a TableDoesNotExist exception which gets thrown during schema creation (so it blocks any further testing for us of the many to many auditing feature).

@VincentLanglet VincentLanglet merged commit 28b46c6 into sonata-project:1.x Feb 13, 2023
@VincentLanglet
Copy link
Member

Thanks

@X-Coder264 X-Coder264 deleted the fix-self-referencing-many-to-many branch February 13, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants