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

[Updated #622] Added configuration option to disable auditing for object associations #644

Open
wants to merge 2 commits into
base: 1.x
Choose a base branch
from

Conversation

vityachis
Copy link

@vityachis vityachis commented Jan 15, 2025

Subject

Pull request allows you to globally disable building a database scheme, and attempt to audit object relationships.
I am targeting this branch, because it is a new feature.

This is the updated PR #622.

Closes #601.

Changelog

### Added
- New configuration option `disable_associations` to disable association tracking.

@vityachis vityachis changed the title Added configuration option to disable auditing for object associations [Updated] Added configuration option to disable auditing for object associations Jan 15, 2025
@vityachis vityachis changed the title [Updated] Added configuration option to disable auditing for object associations [Updated #622] Added configuration option to disable auditing for object associations Jan 15, 2025
Copy link
Member

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

As recommended by @phansys in #622 (review)

This PR would need tests for audit results as proof it works without unexpected exceptions.

@@ -216,7 +216,7 @@ public function find($className, $id, $revision, array $options = [])
$columnName = $idKeys[0];
} elseif (isset($classMetadata->fieldMappings[$idField])) {
$columnName = self::getMappingColumnNameValue($classMetadata->fieldMappings[$idField]);
} elseif (isset($classMetadata->associationMappings[$idField]['joinColumns'])) {
} elseif (!$this->config->areAssociationsDisabled() && isset($classMetadata->associationMappings[$idField]['joinColumns'])) {
Copy link
Member

Choose a reason for hiding this comment

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

If

isset($classMetadata->associationMappings[$idField]['joinColumns'])

but the associations are disabled you now won't enter in this elseif, so you will go in the else

throw new \RuntimeException('column name not found for'.$idField);
  • Is it an expected behavior to get an exception ?
  • I would expect a better error message

So I think the logic should be

elseif (isset($classMetadata->associationMappings[$idField]['joinColumns'])) {
     if ($this->config->areAssociationsDisabled()) {
         // custom behavior or error message
     } else {
         $columnName = $classMetadata->associationMappings[$idField]['joinColumns'][0]['name'];
     }
} else {
     ...
}

@@ -113,6 +113,14 @@ public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $eventArgs)
$revIndexName = $this->config->getRevisionFieldName().'_'.md5($revisionTable->getName()).'_idx';
$revisionTable->addIndex([$this->config->getRevisionFieldName()], $revIndexName);

if (!$this->config->areForeignKeysDisabled()) {
$this->createForeignKeys($revisionTable, $revisionsTable);
Copy link
Member

Choose a reason for hiding this comment

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

You now create ForeignKey before association.

I think it's better to move the foreach ($cm->associationMappings as $associationMapping) { inside a

if (!$this->config->areAssociationsDisabled()) {

to avoid impacts.

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.

Ignore related tables for auditiong
2 participants