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

calling parent on localized entry does not return parent in same locale #145

Open
inveterateliterate opened this issue Oct 15, 2020 · 0 comments · May be fixed by #146
Open

calling parent on localized entry does not return parent in same locale #145

inveterateliterate opened this issue Oct 15, 2020 · 0 comments · May be fixed by #146

Comments

@inveterateliterate
Copy link

inveterateliterate commented Oct 15, 2020

Expectation
When calling a localized entry through the gem, I expect that traversing the hierarchy of the model will also return entries with localized fields for that locale. That is, when calling child.parent, or child.children in a locale other than my default, I expect both the parent and the children to be returned in that locale.

I hope I'm just missing a parameter or option or configuration or something!

Observation
When we call parent records for a localized entry through the gem, the parent's fields are not localized with locale of the originally fetched entry.

It seems that child records are getting returned in the same locale as the parent though, as expected.

For example
A content model called Publication, which has a has-many references with a model called Chapter. In our Chapter model class, we have belongs_to_many :publications, and in our Publication model class we have has_many :chapters.

When we fetch a Chapter entry in French for example (chapter = Chapter.locale('fr').load.first), I see the chapter's fields in French.

When I call chapter.publication, the resulting publication's fields are in English. When I inspect the publication's locale, I see it comes back as 'en-US' (my default locale).

I do notice that calling chapter.pages (a child of chapter) provides me with page entries with fields in French.

However I also noticed that calling my original chapter in French back from its publication: chapter.publication.chapters.first yields a chapter instance in the default locale, rather than my original entry, as described here: https://github.com/contentful/contentful_model/blob/master/lib/contentful_model/associations/belongs_to_many.rb#L38

Things I tried
Calling child.parent.locale(locale) > does not seem to be an option
On the Chapter class tried to pass an option to the belongs_to_many method as described here: https://github.com/contentful/contentful_model/blob/master/lib/contentful_model/associations/belongs_to_many.rb

tried passing an option of locale but got a wrong arguments error. In any case I do not see where other option keys outside the defaults are being considered in the fetch for the parent.

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 a pull request may close this issue.

1 participant