-
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
[Question] CamelCasing included relationships #343
Comments
This is a bit tricky if you don't want to change $defaultIncludes. You could do a quick extending serializer like this:
Then pass it to the manager like this: But this will camel case all of the keys, and you may just want to camel case included resource keys? This may be hard to do without giving the serializer a list of keys to only look for, specific to your application. But there may be an option I'm not thinking of that someone else can chime in with. |
Hey Brad! I've adapted your serializer but it doesn't seem to work for included items. Though even if it did, wouldn't this fix the problem at the "wrong" level? I.e., at serialization level instead of transformation level. |
@renspoesse you should be able to change the key in $default_includes to camel case and have it work. Have you tried that? |
Sorry about that -- it looks like I forgot a filterIncludes() override in my serializer, but it would be implemented in the same fashion as the other methods if you decided to use it. I agree with you about this being more appropriate in the transformation domain, but I'm not sure how it could be done easily. If you take a look at TransformerAbstract::includeResourceIfAvailable(), you'll see that it's really the $default_includes/$available_includes strings that dictate the key names you want to camel case. You could extend TransformerAbstract and override includeResourceIfAvailable() in a transformer that your model transformers then implement, but then you're overriding a private method implied to be "final." Though I may be missing another option that someone else can point out. |
@bradbforbes thanks, we've extended TransformerAbstract to fix it (for now)! You're right though, we had to override a private method so I still think this is a bit of an issue in flexibility of the transformer. |
Any solution to this yet? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 4 weeks if no further activity occurs. Thank you for your contributions. |
I'm trying to include a relationship and CamelCase its key in the output. Is there a way to do this in Fractal without altering the function name in the model?
Model:
Transformer:
The JSON output that I'd like:
Thanks in advance for any answer!
The text was updated successfully, but these errors were encountered: