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

Translation as JSON object instead of string when used with belongsTo relationship #463

Open
afonsosantos opened this issue Oct 24, 2024 · 0 comments

Comments

@afonsosantos
Copy link

Hi there!

First of all, thank you for the work on this library.

We are using this library with Laravel 11, and recently discovered what seems like a bug when a translated model is fetched using belongsTo relationship.

We have a model CategoryRelation that is related to Category model. Now, this category model has a translatable field description.

// CategoryRelation.php

public function category()
{
    return $this->belongsTo(Category::class, 'parent_category_code', 'code');
}

When fetched in a controller from the Laravel Eloquent ORM, this comes as:

{
    "related_category": {
        "name": { "pt": "ABC" }
    },
}

(redacted for simplicity)

In all other places where translatable fields are fetched, the library does a great job fetching the correct value and returning it as a single string. This is the only situation where that does not ocurr.

Hope this was clear. In case any more information is needed, feel free to ask.

Thanks!

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

1 participant