parse-community / ParseReact

Seamlessly bring Parse data into your React applications.
https://parseplatform.org
Other
1.3k stars 209 forks source link

.first() - selecting single object from parse #118

Open Guro opened 9 years ago

Guro commented 9 years ago

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

Gyran commented 9 years ago

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!

treeder commented 8 years ago

+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 commented 8 years ago

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