orm isRelatedById method

This commit is contained in:
Yuri Kuznetsov
2023-11-08 11:22:38 +02:00
parent 930f706dd3
commit c95be2f54e
10 changed files with 132 additions and 72 deletions
@@ -106,15 +106,16 @@ class RDBRelationSelectBuilder
return $this->createSelectBuilder()->clone($newQuery);
}
protected function createSelectBuilder(): SelectBuilder
private function createSelectBuilder(): SelectBuilder
{
return new SelectBuilder();
}
protected function getMapper(): RDBMapper
private function getMapper(): RDBMapper
{
$mapper = $this->entityManager->getMapper();
/** @noinspection PhpConditionAlreadyCheckedInspection */
if (!$mapper instanceof RDBMapper) {
throw new LogicException();
}
@@ -155,7 +156,7 @@ class RDBRelationSelectBuilder
* @param array<string|int, mixed> $where
* @return array<string|int, mixed>
*/
protected function applyMiddleAliasToWhere(array $where): array
private function applyMiddleAliasToWhere(array $where): array
{
$transformedWhere = [];
@@ -293,7 +294,7 @@ class RDBRelationSelectBuilder
* * `where(string $key, string $value)`
*
* @param WhereItem|array<int|string, mixed>|string $clause A key or where clause.
* @param mixed[]|scalar|null $value A value. Should be omitted if the first argument is not string.
* @param array<int, mixed>|scalar|null $value A value. Should be omitted if the first argument is not string.
*/
public function where($clause = [], $value = null): self
{
@@ -322,8 +323,8 @@ class RDBRelationSelectBuilder
* * `having(array $clause)`
* * `having(string $key, string $value)`
*
* @param WhereItem|array<mixed, mixed>|string $clause A key or where clause.
* @param mixed[]|string|null $value A value. Should be omitted if the first argument is not string.
* @param WhereItem|array<int|string, mixed>|string $clause A key or where clause.
* @param array<int, mixed>|string|null $value A value. Should be omitted if the first argument is not string.
*/
public function having($clause = [], $value = null): self
{
@@ -411,7 +412,7 @@ class RDBRelationSelectBuilder
return $this->group($groupBy);
}
protected function getMiddleTableAlias(): ?string
private function getMiddleTableAlias(): ?string
{
if (!$this->isManyMany()) {
return null;
@@ -430,7 +431,7 @@ class RDBRelationSelectBuilder
return $this->middleTableAlias;
}
protected function applyRelationAliasToWhereClauseKey(string $item): string
private function applyRelationAliasToWhereClauseKey(string $item): string
{
if (!$this->isManyMany()) {
return $item;
@@ -445,7 +446,7 @@ class RDBRelationSelectBuilder
* @param array<int|string, mixed> $where
* @return array<int|string, mixed>
*/
protected function applyRelationAliasToWhereClause(array $where): array
private function applyRelationAliasToWhereClause(array $where): array
{
if (!$this->isManyMany()) {
return $where;
@@ -457,10 +458,6 @@ class RDBRelationSelectBuilder
$transformedKey = $key;
$transformedValue = $value;
if (is_int($key)) {
$transformedKey = $key;
}
if (is_string($key)) {
$transformedKey = $this->applyRelationAliasToWhereClauseKey($key);
}
@@ -475,7 +472,7 @@ class RDBRelationSelectBuilder
return $transformedWhere;
}
protected function isManyMany(): bool
private function isManyMany(): bool
{
return $this->relationType === Entity::MANY_MANY;
}
@@ -484,7 +481,7 @@ class RDBRelationSelectBuilder
* @param Collection<Entity> $collection
* @return Collection<Entity>
*/
protected function handleReturnCollection(Collection $collection): Collection
private function handleReturnCollection(Collection $collection): Collection
{
if (!$collection instanceof SthCollection) {
return $collection;
@@ -499,6 +496,7 @@ class RDBRelationSelectBuilder
/**
* @return mixed
* @noinspection PhpSameParameterValueInspection
*/
private function getRelationParam(string $param)
{