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

Omitting availableIncludes breaks defaultIncludes #58

Closed
nielsiano opened this issue May 30, 2014 · 5 comments
Closed

Omitting availableIncludes breaks defaultIncludes #58

nielsiano opened this issue May 30, 2014 · 5 comments

Comments

@nielsiano
Copy link

I updated, and was looking straight into lucifers eyes by doing so. Using include instead of embed now works. BUT, In some of my transformers I had specified the $defaultIncludes array and omitted the $availableIncludes array. It worked before updating, but now the defaultIncludes aren't included in the output. But i found that if i added the $availableIncludes = []; in the transformer it worked.

Am I missing something here?

use League\Fractal\TransformerAbstract;

class GoalTransformer extends TransformerAbstract {

    protected $defaultIncludes = ['user'];

    // why is this needed?
    protected $availableIncludes = [];

    /**
     * Transform a Goal entity into a generic array.
     *
     * @param  \Orly\Goal $goal
     * @return array
     */
    public function transform(Goal $goal)
    {
        return [
            'id'       => (int) $goal->id,
            'match_id' => (int) $goal->match_id,
            'minute'   => (int) $goal->minute
        ];
    }

    /**
     * Include User for Goalscorer
     *
     * @param  \Orly\Goal $goal
     * @return array
     */
    public function includeUser(Goal $goal)
    {
        $user = $goal->user;

        return $this->item($user, new UserTransformer);
    }

}
@philsturgeon
Copy link
Member

Sounds like a bug to me. Do you think you could patch this one? It shouldn’t be all that hard to write a failing test, then fix it. If you could even just write the failing test for me then I could fix it/

I’ve spent so much time on open-source stuff this week I’m drastically behind on a project. >.<

@nielsiano
Copy link
Author

I'll see what I can do. :)

@robclancy
Copy link

Just spent too long with this issue. I had to add 'user' to the availableIncludes array to get it to work.

@nielsiano
Copy link
Author

Still haven't had time to dig further into this. But yes, setting the availableIncludes will solve it for now.

@philsturgeon
Copy link
Member

Thanks for having a run at it both of you. I fixed it in master and I'll tag up a release at some point.

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

3 participants