Skip to content

Commit

Permalink
fix getKey method
Browse files Browse the repository at this point in the history
  • Loading branch information
alphasoft-fr committed Mar 28, 2024
1 parent 39bc645 commit 0b99393
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Entity/AsEntity.php
Expand Up @@ -47,7 +47,7 @@ final public function has(string $property): bool
return array_key_exists($property, $this->attributes);
}

final public function getKey(): string
final public function _getKey(): string
{
return static::class . $this->getPrimaryKeyValue();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Repository/Repository.php
Expand Up @@ -123,7 +123,7 @@ public function insert(AsEntity $entity): int
$lastId = $connection->lastInsertId();
if ($lastId !== false) {
$entity->set($primaryKeyColumn, ctype_digit($lastId) ? (int) $lastId : $lastId);
$this->cache->set($entity->getKey(), $entity);
$this->cache->set($entity->_getKey(), $entity);
$entity->setEntityManager($this->manager);
}
return $rows;
Expand Down Expand Up @@ -151,7 +151,7 @@ public function update(AsEntity $entity, array $arguments = []): int
}
QueryHelper::generateWhereQuery($query, array_merge([$primaryKeyColumn => $entity->getPrimaryKeyValue()], $this->mapPropertiesToColumn($arguments)));
$value = $query->executeStatement();
$this->cache->invalidate($entity->getKey());
$this->cache->invalidate($entity->_getKey());
return $value;
}

Expand All @@ -166,7 +166,7 @@ public function delete(AsEntity $entity): int
$query->delete($this->getTableName())
->where($entity::getPrimaryKeyColumn() . ' = ' . $query->createPositionalParameter($entity->getPrimaryKeyValue()));

$this->cache->invalidate($entity->getKey());
$this->cache->invalidate($entity->_getKey());
$entity->set($entity::getPrimaryKeyColumn(), null);
$entity->setEntityManager(null);
unset($entity);
Expand Down Expand Up @@ -252,7 +252,7 @@ final protected function createModel(array $data): AsEntity
$entity->hydrate($data);
}else {
$entity = ModelFactory::createModel($entityName, $data);
$this->cache->set($entity->getkey(), $entity);
$this->cache->set($entity->_getKey(), $entity);
}

$entity->setEntityManager($this->manager);
Expand Down

0 comments on commit 0b99393

Please sign in to comment.