Skip to content

Commit

Permalink
Merge branch 'master' into l11
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Feb 7, 2024
2 parents 4a4633c + 08ffc2e commit 20f6f69
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/Eloquent/Relations/Traits/RetrievesIntermediateTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -178,4 +178,14 @@ protected function prefix($accessor)
{
return '__'.$accessor.'__';
}

/**
* Get the intermediate tables.
*
* @return array
*/
public function getIntermediateTables(): array
{
return $this->intermediateTables;
}
}
7 changes: 7 additions & 0 deletions tests/IntermediateTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 20f6f69

Please sign in to comment.