A question regarding populate with the following data structure:
actions: {
actionId: {
goalId: 'goalId1',
done: false
},
actionId2: {
goalId: 'goalId1',
done: false
}
}
goals: {
goalId1: {
text: 'Goal title'
}
}
__How would I go about populating goals with actions?__
Conditions:
First, I would suggest taking the pattern of storing data how it will be viewed (i.e. storing a list of actions within goals). This is actually follows Firebase's Docs on "creating structured data that scales":
actions: {
actionId: {
goalId: 'goalId1',
done: false
},
actionId2: {
goalId: 'goalId1',
done: false
}
}
goals: {
goalId1: {
text: 'Goal title',
actions: {
actionId: true,
actionId2: true
}
}
}
Then when calling, you can list goals with populated actions like so:
const populates = [{ child: 'actions', root: 'actions' }]
@firebaseConnect(() => ([
{ path: 'goals', populates }
]))
or actions with the associated goal populated like this:
const populates = [{ child: 'goalId', root: 'goals' }]
@firebaseConnect(() => ([
{ path: 'actions', populates }
]))
Thanks for the help!
I am working on implementing the above, but it doesn't seem to work. I have created the recommended structure.
My code:
const populates = [{ child: 'actions', root: 'actions' }]
@firebaseConnect(() => ([ { path: 'goals', populates } ]))
@connect(({ firebase }) => ({
users: populatedDataToJS(firebase, 'goals', populates),
}))
The result is an unmodified object of action ids, i.e.
actions: {
actionId: true,
actionId2: true
}
Any ideas?
Package version: 1.2.2
That seems like it should be working correctly. I will attempt to replicate using the simple example and get back to you.
Right you are!
It seems that there is an issue gathering the data when populating a parameter that is a Firebase lists (key: true) within each item in a list.
I've started a branch for v1.2.3 where I have fixed this issue and added tests that will make sure that this doesn't break in the future. Trying to release it pretty soon (hopefully tomorrow).
v1.2.3 should hopefully solve this issue, but I will leave it open until that is confirmed.
Great news! I can confirm that this now works as expected. Thanks a lot!
Glad to hear.
There is a unit test for this pattern now too, so it shouldn't be an issue moving forward.