flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
43 stars 5 forks source link

When changing settings.locale, content.get({entryId: 'fl_id'}) returns undefined; #74

Closed ribalnasr closed 5 years ago

ribalnasr commented 5 years ago

hello, i have a document in both 'en-US' and 'ar' locales. after i switch to 'ar' by running settings.setLocale('ar')

when i run

content.get({
    schemaKey: 'some_key'
})

it returns the correct array of docs in the specified language.

however when try to retrieve one doc by id when language is 'ar', as follows,

content.get({ // or .subscribe()
    entryId: 'DFkoPbCRT2MiTFnEL1Z7',
})

it returns undefined. i tried it using both the firestore ID and the flamelink id (_flmeta.fl_id).

jperasmus commented 5 years ago

hi, you will have to specify the schemaKey as well when using entryId. Can you try that, please?

ribalnasr commented 5 years ago

yep i did that, still no result. :(

jperasmus commented 5 years ago

Are the _fl_meta_.fl_id values the same for your ar and en-US entries? They should be the same for the same entry in the Flamelink app, whereas the Firestore doc ID should be unique across locales.

ribalnasr commented 5 years ago

true

ribalnasr commented 5 years ago

reminder: am on firestore.

jperasmus commented 5 years ago

Yeah, the _fl_meta_.fl_id was specifically introduced for Firestore. The RTDB structure leans itself to using the exact same ID for the node because the data is nested.

Can you paste your 2 entries' data here so that I can see how they are created? You can remove any confidential data if needed..mostly interested in the _fl_meta_ object and id.

ribalnasr commented 5 years ago

sure, here you go:

// en-US:
_fl_meta_: {
    createdBy: "W9XxXn6zJSgQ7mRbGBAO2KFw6s23"
    createdDate: April 29, 2019 at 12:49:01 AM UTC+3
    docId: "h1I2hT1nBUq2HcUCRyR9"
    env: "production"
    fl_id: "h1I2hT1nBUq2HcUCRyR9"
    locale: "en-US"
    schema: "channels"
    schemaRef: /fl_schemas/channels
    schemaType: "collection"
}
id: "h1I2hT1nBUq2HcUCRyR9"
name: "rr"
project: /fl_content/LcZbMcRxlwf5ky8Z64uj

// ar:
_fl_meta_: {
    createdBy: "W9XxXn6zJSgQ7mRbGBAO2KFw6s23"
    createdDate: May 20, 2019 at 4:54:55 PM UTC+3
    docId: "z3eO55yKfU2EZ4pztMda"
    env: "production"
    fl_id: "h1I2hT1nBUq2HcUCRyR9"
    locale: "ar"
    schema: "channels"
    schemaRef: /fl_schemas/channels
    schemaType: "collection"
}
id: "z3eO55yKfU2EZ4pztMda"
name: "rr arabic"
project: /fl_content/LcZbMcRxlwf5ky8Z64uj
jperasmus commented 5 years ago

Out of interest, is it only returning undefined after you set a new locale or does it return undefined always for your “ar” locale?

ribalnasr commented 5 years ago

i set the locale to ar at the beginning with a button, and the queries come after it on independent triggers in other pages. switching back to en-us everything works again normally.

maybe it's worth mentioning that usually when the result is empty it returns null, but in this case here it's returning undefined.

jperasmus commented 5 years ago

I found the issue - a fix will be available soon.

jperasmus commented 5 years ago

Fix available in v1.0.0-alpha.19

ribalnasr commented 5 years ago

yep.. working now!

i have another locales-related issue for you later today. after i make sure its not from my side :)

jperasmus commented 5 years ago

haha, okay, I'll wait for that one then. :)