Skip to content

Commit 4986b0f

Browse files
committed
fix(DB): NavigationMapper has to override insert due to not having an id
… column Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 520426d commit 4986b0f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/Db/ContextNavigationMapper.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,31 @@ public function setDisplayModeByShareId(int $shareId, int $displayMode, string $
4343
return $this->insertOrUpdate($entity);
4444
}
4545

46+
// we have to overwrite QBMapper`s insert() because we do not have
47+
// an id column in this table. Sad.
48+
public function insert(Entity $entity): Entity {
49+
// get updated fields to save, fields have to be set using a setter to
50+
// be saved
51+
$properties = $entity->getUpdatedFields();
52+
53+
$qb = $this->db->getQueryBuilder();
54+
$qb->insert($this->tableName);
55+
56+
// build the fields
57+
foreach ($properties as $property => $updated) {
58+
$column = $entity->propertyToColumn($property);
59+
$getter = 'get' . ucfirst($property);
60+
$value = $entity->$getter();
61+
62+
$type = $this->getParameterTypeForProperty($entity, $property);
63+
$qb->setValue($column, $qb->createNamedParameter($value, $type));
64+
}
65+
66+
$qb->executeStatement();
67+
68+
return $entity;
69+
}
70+
4671
// we have to overwrite QBMapper`s update() because we do not have
4772
// an id column in this table. Sad.
4873
public function update(Entity $entity): ContextNavigation {

0 commit comments

Comments
 (0)