Merge pull request #19659 from nextcloud/techdebt/17486/allow-non-integer-ids-in-entity-mapper

Allow non integer ids in Entity Mapper
This commit is contained in:
Roeland Jago Douma 2020-02-27 09:12:35 +01:00 committed by GitHub
commit 72cc8270cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -89,9 +89,11 @@ abstract class QBMapper {
public function delete(Entity $entity): Entity {
$qb = $this->db->getQueryBuilder();
$idType = $this->getParameterTypeForProperty($entity, 'id');
$qb->delete($this->tableName)
->where(
$qb->expr()->eq('id', $qb->createNamedParameter($entity->getId()))
$qb->expr()->eq('id', $qb->createNamedParameter($entity->getId(), $idType))
);
$qb->execute();
return $entity;
@ -126,6 +128,7 @@ abstract class QBMapper {
$qb->execute();
if($entity->id === null) {
// When autoincrement is used id is always an int
$entity->setId((int)$qb->getLastInsertId());
}
@ -191,8 +194,10 @@ abstract class QBMapper {
$qb->set($column, $qb->createNamedParameter($value, $type));
}
$idType = $this->getParameterTypeForProperty($entity, 'id');
$qb->where(
$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
$qb->expr()->eq('id', $qb->createNamedParameter($id, $idType))
);
$qb->execute();