Skip to content

Commit

Permalink
[Translatable] Ignore notInsertable columns…
Browse files Browse the repository at this point in the history
in postPersist hook.

Respect the column's metadata and don't attempt to insert a column
that's flagged to be not-insertable.
  • Loading branch information
dgrothaus-mc committed Jul 2, 2024
1 parent e85560e commit efc1857
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ a release.
---

## [Unreleased]
### Fixed
- Translatable: Ignore notInsertable columns in postPersist hook

## [3.16.1]
### Fixed
Expand Down
10 changes: 8 additions & 2 deletions src/Translatable/Mapping/Event/Adapter/ODM.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,15 @@ public function insertTranslationRecord($translation)
$data = [];

foreach ($meta->getReflectionProperties() as $fieldName => $reflProp) {
if (!$meta->isIdentifier($fieldName)) {
$data[$meta->getFieldMapping($fieldName)['name']] = $reflProp->getValue($translation);
if ($meta->isIdentifier($fieldName)) {
continue;
}
$fieldMappings = $meta->getFieldMapping($fieldName);
if (($fieldMappings['notInsertable'] ?? false) === true) {
continue;
}

$data[$meta->getColumnName($fieldName)] = $reflProp->getValue($translation);
}

$insertResult = $collection->insertOne($data);
Expand Down
11 changes: 8 additions & 3 deletions src/Translatable/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,16 @@ public function insertTranslationRecord($translation)
$data = [];

foreach ($meta->getReflectionProperties() as $fieldName => $reflProp) {
if (!$meta->isIdentifier($fieldName)) {
$data[$meta->getColumnName($fieldName)] = $reflProp->getValue($translation);
if ($meta->isIdentifier($fieldName)) {
continue;
}
$fieldMappings = $meta->getFieldMapping($fieldName);
if (($fieldMappings['notInsertable'] ?? false) === true) {
continue;
}
}

$data[$meta->getColumnName($fieldName)] = $reflProp->getValue($translation);
}
$table = $meta->getTableName();
if (!$em->getConnection()->insert($table, $data)) {
throw new RuntimeException('Failed to insert new Translation record');
Expand Down

0 comments on commit efc1857

Please sign in to comment.