ParseReact icon indicating copy to clipboard operation
ParseReact copied to clipboard

.first() - selecting single object from parse

Open Guro opened this issue 10 years ago • 3 comments

Hello im trying to select single object not an array of objects, how that is possible? as a parse javascript sdk docs says, it must be done using .first(), but i cant implement it in parseReact.

my query looks like this:

 observe(props, state) {
        return {
            post: (new Parse.Query('Post')).include('author').equalTo('objectId',props.params.postId)
        };
    }

but it selects array with 1 object, adding .first() at the and returns nothing

Guro avatar Sep 17 '15 18:09 Guro

I don't think it's possible to observe a single object. What I do is that I have a Query that does what yours is doing. Then I have function that returns my object.

getPost() {
  return this.data.post[0];
}

With that I can also easy check if my post has been fetched or not by just checking if getPost returns anything. But I think it would be a good feature if you could subscribe to a single object!

Gyran avatar Sep 17 '15 21:09 Gyran

+1 on getting a single object. I've been pulling in single objects using the regular Parse SDK which works fine, but the object you get back isn't compatible with ParseReact mutations. For instance, you can't update an object like this:

var mutation = ParseReact.Mutation.Set(myParseOb, event);

treeder avatar Nov 25 '15 21:11 treeder

More on the issue I'm talking about here: https://github.com/ParsePlatform/ParseReact/issues/45

treeder avatar Nov 25 '15 21:11 treeder