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.
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, orchild.childrenin 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 calledChapter. In ourChaptermodel class, we havebelongs_to_many :publications, and in ourPublicationmodel class we havehas_many :chapters.When we fetch a
Chapterentry in French for example (chapter = Chapter.locale('fr').load.first), I see thechapter's fields in French.When I call
chapter.publication, the resultingpublication's fields are in English. When I inspect thepublication'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 withpageentries with fields in French.However I also noticed that calling my original
chapterin French back from its publication:chapter.publication.chapters.firstyields 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#L38Things I tried
Calling
child.parent.locale(locale)> does not seem to be an optionOn the
Chapterclass tried to pass an option to thebelongs_to_manymethod as described here: https://github.com/contentful/contentful_model/blob/master/lib/contentful_model/associations/belongs_to_many.rbtried passing an option of
localebut 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.