diff --git a/README.md b/README.md index e981745..06d3a4c 100644 --- a/README.md +++ b/README.md @@ -580,7 +580,7 @@ class RoleUser extends Pivot } ``` -Use `setAlias()` to specify a table alias when concatenating existing relationships (Laravel 6+): +Use `setAlias()` to specify a table alias when concatenating existing relationships: ```php class Post extends Model diff --git a/docker-compose.yml b/docker-compose.yml index e5d07a3..d4e5a97 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,8 @@ version: '3.8' services: - php82: - build: - context: . - dockerfile: .docker/php82.Dockerfile + php8.2: + image: ghcr.io/staudenmeir/php:8.2 working_dir: /var/www/html networks: - test @@ -20,7 +18,7 @@ services: - .:/var/www/html:delegated - .docker/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini mysql: - image: 'mysql:latest' + image: 'mysql:5.7' environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: test diff --git a/src/Eloquent/Relations/Traits/RetrievesIntermediateTables.php b/src/Eloquent/Relations/Traits/RetrievesIntermediateTables.php index 2898c37..102f2a4 100644 --- a/src/Eloquent/Relations/Traits/RetrievesIntermediateTables.php +++ b/src/Eloquent/Relations/Traits/RetrievesIntermediateTables.php @@ -100,7 +100,7 @@ protected function hydrateIntermediateRelations(array $models) foreach ($intermediateTables as $accessor => $intermediateTable) { $prefix = $this->prefix($accessor); - if (Str::contains($accessor, '.')) { + if (str_contains($accessor, '.')) { [$path, $key] = preg_split('/\.(?=[^.]*$)/', $accessor); } else { [$path, $key] = [null, $accessor]; @@ -178,4 +178,14 @@ protected function prefix($accessor) { return '__'.$accessor.'__'; } + + /** + * Get the intermediate tables. + * + * @return array + */ + public function getIntermediateTables(): array + { + return $this->intermediateTables; + } } diff --git a/tests/IntermediateTableTest.php b/tests/IntermediateTableTest.php index d30c267..d0669ec 100644 --- a/tests/IntermediateTableTest.php +++ b/tests/IntermediateTableTest.php @@ -96,4 +96,11 @@ public function testChunk() $this->assertTrue($results[0]->relationLoaded('post')); }); } + + public function testGetIntermediateTables() + { + $comments = Country::find(1)->comments(); + + $this->assertEquals([], $comments->getIntermediateTables()); + } }