prescottprue / react-redux-firebase

Redux bindings for Firebase. Includes React Hooks and Higher Order Components.
https://react-redux-firebase.com
MIT License
2.55k stars 559 forks source link

Make the populate function account for the childParam option #1083

Closed danielo515 closed 2 years ago

danielo515 commented 3 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

I noticed that the populate function doesn't take into account if you want to just pick a childParam. I had to patch it to enable this behaviour and I think it may help others. Will you consider to merge a pull request with this change?

Here is the diff that solved my problem:

diff --git a/node_modules/react-redux-firebase/src/utils/populate.js b/node_modules/react-redux-firebase/src/utils/populate.js
index efce67f..669fc03 100644
--- a/node_modules/react-redux-firebase/src/utils/populate.js
+++ b/node_modules/react-redux-firebase/src/utils/populate.js
@@ -75,7 +75,7 @@ export function getPopulateChild(firebase, populate, id) {
   return firebase
     .database()
     .ref()
-    .child(`${populate.root}/${id}`)
+    .child(`${populate.root}/${id}${populate.childParam ? `/${populate.childParam}` : ''}` )
     .once('value')
     .then((snap) =>
       // Return id if population value does not exist
danielo515 commented 3 years ago

I have forked and patched this. I can open a PR if you are interested