Alberto Garrido
Alberto Garrido

Reputation: 555

Parse.com Query is empty even though I have data on the server

I'm newbie using parse.com I watched a video tutorial very useful, and now I'm doing my first app. But apparently I think I'm doing something wrong:

I have a Class called MyClass that includes a use. I added a row. In my javascript code I try a simple query by objectId but I'm getting empty results:

var MyClass = Parse.Object.extend("MyClass");
var query = new Parse.Query(MyClass);
query.equalTo("objectId","kX6lNWOpPs");
query.include("user");
query.find({
    success: function(results){
        console.log("query ok!");
        console.log(results);
    },
    error: function(error){
        console.log(error);
    }
});

It looks that simple that I'm not sure if I'm doing a huge mistake. The result in the console is:

query ok!
[]

In my class there's a row for sure. I've refreshed the site, even logged out in parse.com. Also the ID is correct, verified a lot of times.

The funny part is that in the video tutorial we used the exact same code, with different classes and data, but same structure.

Thanks in advance for any help. :)

EDIT: if I remove the equalTo and the include functions the results are the same. EDIT 2: My error was different. I'm ashamed about it :S I had a typo in the Class name: I was using PlayerKey instead of PlayerKeys. The full name doesn't fit on the sidebar column. One of those stupid errors that make you crazy. Besides Parse didn't told me that the class doesn't exists or create it on the query, that only happens as far as I know when you extend. As I said, I'm so newbie :)

Upvotes: 1

Views: 165

Answers (1)

Wain
Wain

Reputation: 119031

If you have the object id then you don't need to run a query as such, you can just get the object with the query:

query.get("kX6lNWOpPs", {
  success: function(obj) {
    console.log("query ok!");
    console.log(obj.id);
  },
  error: function(object, error) {
    console.log(error);
  }
});

Note that to use include the user column should be of Pointer type.

Upvotes: 1

Related Questions