redux-firestore icon indicating copy to clipboard operation
redux-firestore copied to clipboard

feat(query): populate support in get queries

Open prescottprue opened this issue 6 years ago • 5 comments

Do you want to request a feature or report a bug?
Feature

What is the current behavior? Population only works with setListeners and setListener

What is the expected behavior? Population also works with get

Which versions of dependencies, and which browser are affected by this issue? Did this work in previous versions or setups? v0.6.0 and v1.0.0-alpha

Steps to reproduce and if possible a minimal demo of the problem via codesandbox or similar.

More details and an example here: https://github.com/prescottprue/react-redux-firebase/issues/571

prescottprue avatar Nov 23 '18 17:11 prescottprue

Hello! Just following this up, are we expecting that you should be able to do this:

_refresh = async () => {
    const { firestore, photo } = this.props;
    const doc = await firestore.get({
      collection: "photos",
      doc: photo.id,
      populate: [{ child: "user", root: "users" }]
    });
    const data = doc.data();
    this.setState({
      photo: data
    });
  };

Should it also be possible to populate a single document for a SHOW route? I don't believe this is possible either unless I am missing something?

const Screen = compose(
  connect(
    mapStateToProps,
    mapDispatchToProps
  ),
  firestoreConnect(props => {
    if (!props.params.id) return [];
    return [
      {
        collection: "photos",
        doc: props.params.id,
        populate: [{ child: "user", root: "users" }]
      }
    ];
  })
)(Container);

alexpchin avatar Jan 07 '19 01:01 alexpchin

The setting would be populates, but yes both should be possible. Also, it is often better to have the state connection (i.e. connect) after your firebaseConnect.

prescottprue avatar Jan 07 '19 04:01 prescottprue

When placing the connect after firebaseConnect:

const Screen = compose(
  firestoreConnect(props => {
    console.log(props.params); // <----------- Undefined
    return [];
    // if (!props.params.id) return [];
    // return [
    //   {
    //     collection: "photos",
    //     doc: props.params.id,
    //     populate: populates
    //   }
    // ];
  }),
  connect(
    mapStateToProps,
    mapDispatchToProps
  )
)(Container);

When placing after, it loads. How would you suggest fetching a single doc using params?

alexpchin avatar Jan 07 '19 10:01 alexpchin

Props that are passed shouldn't change regardless of which order you place the HOCs in unless you are getting the params from state (but its seems like you are having them passed from the route through react-router). Can you provide more context into how your component is used?

The complete material example uses route params to load data in the child view but since it is using react-router-dom you can see the params are coming from match.

prescottprue avatar Jan 07 '19 17:01 prescottprue

@prescottprue any plans on making this work (original description of the issue describes my problem)? Realized populate only works when I'm not passing a doc parameter (i.e. not pulling a single document), was confused for a while!

nemo avatar Jan 15 '19 19:01 nemo