knuckleswtf / knuckleswtf/scribe
Unable to do nested eager loading using #[ResponseFromApiResource]
- Dominant language
- PHP
- Stars
- 2.3k
- Forks
- 357
- PR merge metrics
- No merged PRs in 30d
Description
### Scribe version
4.29.0
### PHP version
8.2.8
### Framework
Laravel
### Framework version
10.17.0
### Scribe config
```ruby
try_it_out.enabled => false
auth.enabled => true
auth.default => true
postman.enabled => false
openapi.enabled => false
last_updated => "Last updated: {date:Y-m-d}"
strategies.urlParameters => added Knuckles\Scribe\Extracting\Strategies\UrlParameters\GetFromLumenAPI
strategies.headers => added Knuckles\Scribe\Extracting\Strategies\Headers\GetFromRouteRules: removed [
'override',
[
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
]
strategies.responses => added Knuckles\Scribe\Extracting\Strategies\Responses\ResponseCalls: removed [
'Knuckles\\Scribe\\Extracting\\Strategies\\Responses\\ResponseCalls',
[
'only' => [
'GET *',
],
],
]
```
### What happened?
Thanks for Scribe.
I declared an attribute like this.
```php
#[ResponseFromApiResource(
BookResource::class,
Book::class,
with: ["author.contacts"],
)]
```
Expected (at BookResource):
```php
$this->resource->relationLoaded("author"); // true
$this->resource->author->relationLoaded("contacts"); // true
```
As is:
```php
$this->resource->relationLoaded("author"); // 👍 true
$this->resource->author->relationLoaded("contacts"); // 🆖 false
```
I see a problem here.
https://github.com/knuckleswtf/scribe/blob/695c2a99a70f8c6c1b0dd3bf34d0d70af5ca44fc/src/Extracting/InstantiatesExampleModels.php#L72
I am able to load nested relations as expected until `$factory->create()->load($relations)`,
but the `contacts` relation is lost in `refresh()`.
Sorry if my language is poor and rude.
### Docs
- [X] I've checked [the docs](https://scribe.knuckles.wtf/laravel), the [troubleshooting guide](https://scribe.knuckles.wtf/laravel/troubleshooting), and [existing issues](https://github.com/knuckleswtf/scribe/issues?q=is%3Aissue+), but I didn't find a solution
Contributor guide
Research direction
Start at src/Extracting/InstantiatesExampleModels.php around line 72 and trace the create()->load($relations) flow through refresh(). Reproduce the ResponseFromApiResource example with with: ["author.contacts"]. Done means both author and author.contacts remain loaded in BookResource after example model instantiation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100