Use getFieldValue
for translated relationship attributes.
#697
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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. foren
) 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.