Hi!
I have a profile object:
{
"friends" : {
"-Kp-ky6hOPq-nImOpVGk" : "gsTflZjxoYcdQJUrS6nw6uxLFa93",
"-KyzHhAr6QgdAcqnE5VF" : "frByC4g8cJTxcCNjfL2TWUMj9aR2"
},
"matches" : {
"2LA4QQHfMQhP6Gdk8iaEFvlN1Du2" : 14,
"YxqFK8M2nJOKt0Wz17Fj8sTNY1u1" : 18,
},
"uid" : "GauAnEhTaNOepGJbEmlxTW7Ex7G3"
}
To populate list of friends I just need to add:
@connect(
(state) => ({
profile: populate( state.firebase, 'profile', [ { child: 'friends', root: 'users' }])
})
)
How can I populate matches by keys instead of values or maybe by subfield?
I just don't want to get the full list of users from db, I think there must be a better way.
Also interested how to solve such kind of issues.
Great to know there is interest in this.
If the values are true (i.e a $key: true list) it will populate automatically. If the values are not true (like in the example you provided) - you can provide a function that calculates you population settings (instead of just an array). I'll work on an example to show what I mean.
@prescottprue Thank you!
Do you mean https://github.com/prescottprue/react-redux-firebase/blob/master/src/utils/populate.js#L108 , https://github.com/prescottprue/react-redux-firebase/blob/master/src/helpers.js#L251 and https://github.com/prescottprue/react-redux-firebase/blob/master/src/helpers.js#L264 , am I right?
It'd be great if you could provide an example :slightly_smiling_face:
I would also like to see an example
@prescottprue Could you please help me, how I can provide my own function calculating my population settings (instead of just an array) ?
I am working with firebase and would like to know a better way as well.
@prescottprue happy new year! was hoping you could share your example for this! Thanks!
Hey everyone, just an update:
Got really sick while traveling for the holidays, so I have been out of commission the past few days. Hoping to be back to it early next week, and this is on the list of todo items.
Would be great to see populate function example.:)
any updates on this one?
@iamthefox This is currently in the PR for v2.1.0 due to the API change. There have been a few people asking for this though, so I may try to squeeze it into a patch version (since it isn't breaking) so that we can get it out faster.
Would that be helpful to anyone? Is anyone waiting on this feature and unable to point directly to the PR?
Yes @prescottprue we're waiting for the feature.
The v2.0.5 release includes populateByKey along with unit tests.
As always, reach out if it isn't working as expected. Thanks to all for input.
This new feature have docs in somewhere?
Trying to figure out how to use that
@cubissimo Great call, looks like populateByKey is not in the docs, I'll look into adding it. If you are attempting to force key population, you can do the following:
const populates = [
{
child: 'contacts',
root: 'users',
populateByKey: true // this is needed to force key population when not $key: true
}
]
compose(
firebaseConnect((props) => [
{ path: 'projects', populates }
]),
connect((state) => ({
projects: populate(state.firebase, 'projects', populates)
})
)
NOTE: As already mentioned in the populate docs, things work slightly differently when populating your own profile.
Perfect @prescottprue!
Last but least one doubt.. i've ever to do the populate via child reference correct?
i.e. in a struct like:
/persons
{
"persons":{
"personId1":{
"someprop":"Happy"
}
"personId2":{
"someprop":"Sad"
}
}
}
const populates = [
{
child: '??????', //i dont know if it works because the key is a root property
root: 'users',
populateByKey: true // this is needed to force key population when not $key: true
}
]
compose(
firebaseConnect((props) => [
{ path: 'persons', populates }
]),
connect((state) => ({
projects: populate(state.firebase, 'persons', populates)
})
)
is there a way to work with keys in root of the object?
Tks!
Most helpful comment
Hey everyone, just an update:
Got really sick while traveling for the holidays, so I have been out of commission the past few days. Hoping to be back to it early next week, and this is on the list of todo items.