diff --git a/src/Database/IStructure.php b/src/Database/IStructure.php index 8c09e749..b4b8c8a1 100644 --- a/src/Database/IStructure.php +++ b/src/Database/IStructure.php @@ -58,13 +58,13 @@ function getPrimaryKeySequence(string $table): ?string; * Returns hasMany reference. * If a targetTable is not provided, returns references for all tables. */ - function getHasManyReference(string $table, ?string $targetTable = null): ?array; + function getHasManyReference(string $table): ?array; /** * Returns belongsTo reference. * If a column is not provided, returns references for all columns. */ - function getBelongsToReference(string $table, ?string $column = null): ?array; + function getBelongsToReference(string $table): ?array; /** * Rebuilds database structure cache. diff --git a/src/Database/Structure.php b/src/Database/Structure.php index 72a66300..5d613ea6 100644 --- a/src/Database/Structure.php +++ b/src/Database/Structure.php @@ -114,41 +114,19 @@ public function getPrimaryKeySequence(string $table): ?string } - public function getHasManyReference(string $table, ?string $targetTable = null): ?array + public function getHasManyReference(string $table): array { $this->needStructure(); $table = $this->resolveFQTableName($table); - - if ($targetTable) { - $targetTable = $this->resolveFQTableName($targetTable); - foreach ($this->structure['hasMany'][$table] as $key => $value) { - if (strtolower($key) === $targetTable) { - return $this->structure['hasMany'][$table][$key]; - } - } - - return null; - - } else { - return $this->structure['hasMany'][$table] ?? []; - } + return $this->structure['hasMany'][$table] ?? []; } - public function getBelongsToReference(string $table, ?string $column = null): ?array + public function getBelongsToReference(string $table): array { $this->needStructure(); $table = $this->resolveFQTableName($table); - - if ($column) { - $column = strtolower($column); - return isset($this->structure['belongsTo'][$table][$column]) - ? [$this->structure['belongsTo'][$table][$column], $column] - : null; - - } else { - return $this->structure['belongsTo'][$table] ?? []; - } + return $this->structure['belongsTo'][$table] ?? []; } diff --git a/tests/Database/Structure.phpt b/tests/Database/Structure.phpt index 43490840..c2799b51 100644 --- a/tests/Database/Structure.phpt +++ b/tests/Database/Structure.phpt @@ -148,11 +148,6 @@ class StructureTestCase extends TestCase Assert::same([ 'Books' => ['author_id', 'translator_id'], ], $this->structure->getHasManyReference('authors')); - - Assert::same( - ['author_id', 'translator_id'], - $this->structure->getHasManyReference('authors', 'books'), - ); } @@ -169,13 +164,6 @@ class StructureTestCase extends TestCase 'tag_id' => 'tags', 'book_id' => 'Books', ], $this->structure->getBelongsToReference('books_x_tags')); - - Assert::same( - ['Books', 'book_id'], - $this->structure->getBelongsToReference('books_x_tags', 'book_id'), - ); - - Assert::null($this->structure->getBelongsToReference('books_x_tags', 'non_exist')); }