Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParentScope identifier is set null #38

Closed
JulianBustamante opened this issue Oct 3, 2018 · 2 comments
Closed

ParentScope identifier is set null #38

JulianBustamante opened this issue Oct 3, 2018 · 2 comments

Comments

@JulianBustamante
Copy link
Contributor

JulianBustamante commented Oct 3, 2018

Actual Behavior

I have a resource named Portfolio that includes another resource called Company. So there's a relationship between Portfolio and Company. When the Company is included in the Portfolio resource I need to show some data which is not displayed in another context. In order to check the context in the CompanyTransformer, I need the parentScopes to be properly set. But the Scope for the Portfolio resource is created with a null identifier.

Expected Behavior

The Scope for the Portfolio resource (which is the parentScope for Company) should have an identifier instead of null.

Specifications

spatie/fractalistic 2.7.1
spatie/laravel-fractal 5.3.2

Additional Details

When the wrapper method createData located in Fractal.php line 380 calls createData from the manager, the scopeIdentifier parameter is not passed, so the Scope returned has a null identifier.

Proposed Solution

To pass the scopeIdentifier string (Could be the resourceName) as the second parameter when createData is called in the line 408.

return $this->manager->createData($this->getResource(), $this->resourceName);

A unit test could be

/** @test */
public function it_uses_an_identifier_for_the_scope()
{
    $scope = $this->fractal
        ->collection($this->testBooks, new TestTransformer(), 'books')
        ->parseIncludes('characters')
        ->createData();

    $this->assertEquals('books', $scope->getIdentifier());
}
@freekmurze
Copy link
Member

Thanks for the info! Could you create a PR for this?

@freekmurze
Copy link
Member

Fixed with #39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants