-
Notifications
You must be signed in to change notification settings - Fork 347
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
The Include Key Is Excluded If Include Function Returns null #491
Comments
I think you could do a ternary statement there, and if your relationship is null, call |
Wow ;) There is a transformer function |
It should work. If you are adding a return type, use the |
Im going to close this for now, if you need more help feel free to open this issue again :) |
I still couldn't figure out how to do it 😒
Can you give a bit more detailed explanation? I also found this issue #469 which seems to deal with the same problem. How long do you think it will take until the package covers that feature out of the box? |
I will see if I can get a working example later today. |
so @MannikJ just so I understand you have a model such as |
Your example is not very good, because I would not model a hasMany relation like public function includeUser(Model $model)
{
return $model->user_id
? $this->item($model->user, new UserTransformer)
: $this->null();
} |
ok I will see what I can recreate. |
in the main
|
I would like to include a belongsTo relation via fractal. If requested by the client, the key should always be present in the response object even if it is null.
In the above example the resulting array would not contain the
user
key, but the result should be like this:How can I convince fractal to include the key?
The text was updated successfully, but these errors were encountered: