Skip to content

Use getFieldValue for translated relationship attributes. #697

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

Conversation

bubba169
Copy link

@bubba169 bubba169 commented Jul 6, 2020

Skip trying to get the translated relationship using the laravel relationships as this ends in an error if the translated value is empty. It errors when serialising because it doesn't check for the _id field on the translation table, only the field slug. It also errors if a value is null as it tries to return the field from the parent using the original slug.

Skipping this and going straight through getFieldValue will return the relationship id properly which is what currently happens if the translated values are present. This has the added benefit of fetching the default translated value (e.g. for en) if a translation for the current locale is not available.

Unless there's a better way to use translated relationships that I'm not aware of, this fix allows us to use the feature and work around the relationship issues by using a presenter to fetch the related model by its id.

@RyanThompson RyanThompson merged commit f4b0910 into laravel-streams:1.7 Aug 27, 2020
@RyanThompson
Copy link
Contributor

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants