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

How to populate second-level relational field. #115

Closed ribalnasr closed 4 years ago

ribalnasr commented 4 years ago

hi i have a collection of projects, each project has a relational field of multiple partners and each partner has a logo image.

the final result i expect is as follows:

[
    {
        title: 'Project title',
        partners: [
            {
                name: 'First Partner',
                logo: [{
                    // ...
                    url: 'url_to_image'
                }]
            }
        ]
    }
]

i'm try the following query

.subscribe({
    schemaKey: 'projects',
    populate: ['partners']
})

but the above populate only the partner level and returns the logo as a document reference:

[
    {
        title: 'Project title',
        partners: [
            {
                name: 'First Partner',
                logo:[DocumentReference]
            }
        ]
    }
]

any suggestions?

please note that using populate:true is out of question since it conflicts with my firestore rules, i need to explicit specify each field i need to populate.

ribalnasr commented 4 years ago

nevermind... i finally found that in your docs: https://flamelink.github.io/flamelink-js-sdk/#/api-overview?id=fields

solution:

.subscribe({
    schemaKey: 'projects',
    populate: [{
        field: 'partners',
        fields: ['name', 'logo'],
        populate: ['logo']
    }]
})
jperasmus commented 4 years ago

Thanks, sorry, I missed this issue when it came in. Glad you got it working.