- Added a new @PrimaryKey annotation to replace the too-specific property-wise @Id

This commit is contained in:
Dave Mc Nicoll committed 2022-11-11 13:57:29 +00:00
1 parent 0e8443b1c1
commit b20e537038
6 files changed
+33 -19

No files matched your search

+10 -10
View File
@@ -46,7 +46,7 @@ class Repository
return $this->where($field, $value)->loadOne();
}
public function loadFromPk($value, /* ? stringable */ $primaryKey = null) : ? object
public function loadFromPk($value, null|string|\Stringable $primaryKey = null) : ? object
{
return $primaryKey ? $this->loadOneFromField($primaryKey, $value) : $this->wherePrimaryKey($value)->loadOne();
}
@@ -130,7 +130,7 @@ class Repository
}
}
public function save(/*object|array*/ $entity, ? array $fieldsAndValue = null, bool $replace = false) : bool
public function save(object|array $entity, ? array $fieldsAndValue = null, bool $replace = false) : bool
{
if ( is_array($entity) ) {
$entity = ( new $this->entityClass() )->fromArray($entity);
@@ -198,7 +198,7 @@ class Repository
return $changed;
}
public function insertAll(/* EntityCollection | array */ $collection, int $size = 1000) : int
public function insertAll(EntityCollection|array $collection, int $size = 1000) : int
{
if ( empty($collection) ) {
return 0;
@@ -254,12 +254,12 @@ class Repository
}
}
public function replace(/*object|array*/ $entity, ? array $fieldsAndValue = null) : bool
public function replace(object|array $entity, ? array $fieldsAndValue = null) : bool
{
return $this->save($entity, $fieldsAndValue, true);
}
public function replaceAll(/*EntityCollection|array*/ $collection) : int
public function replaceAll(EntityCollection|array $collection) : int
{
$changed = 0;
@@ -339,7 +339,7 @@ class Repository
}
}
public function removeQueryFragment(/*? Query\Fragment|string*/ $fragment) : self
public function removeQueryFragment(null|Query\Fragment|string|array $fragment) : self
{
foreach((array) $fragment as $item) {
$this->queryBuilder->removeFragment($item);
@@ -381,14 +381,14 @@ class Repository
);
}
public function select(/*array|Stringable*/ $fields, bool $distinct = false) : self
public function select(array|string|\Stringable $fields, bool $distinct = false) : self
{
$this->queryBuilder->select($fields, $distinct);
return $this;
}
public function distinct(/*array|Stringable*/ $fields) : self
public function distinct(array|string|\Stringable $fields) : self
{
$this->queryBuilder->select($fields);
$this->queryBuilder->getFragment(Query\Select::class)->distinct = true;
@@ -642,7 +642,7 @@ class Repository
return $this;
}
public function withSubquery(/*string|array*/ $fields) : self
public function withSubquery(string|array $fields) : self
{
# We skip subqueries when counting results since it should not affect the row count.
if ( $this instanceof Repository\ServerRequestCountRepository ) {
@@ -704,7 +704,7 @@ class Repository
return $this;
}
public function loadCollectionRelation(EntityCollection $collection, /*array|string*/ $fields) : void
public function loadCollectionRelation(EntityCollection $collection, array|string $fields) : void
{
foreach ((array)$fields as $name) {
if (null !== ($relation = $this->entityResolver->searchFieldAnnotation($name, new Annotation\Property\Relation()))) {