Skip to content

Commit

Permalink
fix(DB): NavigationMapper has to override insert due to not having an id
Browse files Browse the repository at this point in the history
… column

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Oct 4, 2024
1 parent 520426d commit 4986b0f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/Db/ContextNavigationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ public function setDisplayModeByShareId(int $shareId, int $displayMode, string $
return $this->insertOrUpdate($entity);
}

// we have to overwrite QBMapper`s insert() because we do not have
// an id column in this table. Sad.
public function insert(Entity $entity): Entity {
// get updated fields to save, fields have to be set using a setter to
// be saved
$properties = $entity->getUpdatedFields();

$qb = $this->db->getQueryBuilder();
$qb->insert($this->tableName);

// build the fields
foreach ($properties as $property => $updated) {
$column = $entity->propertyToColumn($property);
$getter = 'get' . ucfirst($property);
$value = $entity->$getter();

$type = $this->getParameterTypeForProperty($entity, $property);
$qb->setValue($column, $qb->createNamedParameter($value, $type));
}

$qb->executeStatement();

return $entity;
}

// we have to overwrite QBMapper`s update() because we do not have
// an id column in this table. Sad.
public function update(Entity $entity): ContextNavigation {
Expand Down

0 comments on commit 4986b0f

Please sign in to comment.