I'm trying to retrieve a field from a Pointer as suggested on this post but I'm always getting undefined.
This is what my table Publication looks like:
userId -> UsersubCategoryId -> SubCategorytitledescriptionAnd my SubCategory table:
categoryId -> CategorynameisActiveAnd this is my attempt (I only have one row on the table):
var user = Parse.User.current();
var User = Parse.Object.extend("User");
var userQuery = new Parse.Query(User);
userQuery.equalTo("objectId", user.id);
var Publication = Parse.Object.extend("Publication");
var publicationQuery = new Parse.Query(Publication);
publicationQuery.include("subCategoryId");
publicationQuery.matchesQuery("userId", userQuery);
publicationQuery.find({
success: function(publications) {
console.log(publications[0].get("title"));
// This one returns undefined
console.log(publications[0].get("subCategoryId"));
}, error: function(error) {
// Nothing here as suggested by @adolfosrs
console.log(error);
}
});
What I need is:
publications[0].get("subCategoryId").get("name");
But obviously the latter throws:
Uncaught TypeError: Cannot read property 'get' of undefined
If you have Pointers in your parse database like the following, there is no need on working with the objectIds.

The data that you should have is something like this:
Publication:
Pointer <_User>)Pointer <SubCategory>)String)String)SubCategory:
Pointer <Category>)String)boolean)So if you are saving the data as expected the following must work:
var currentUser = Parse.User.current();
var Publication = Parse.Object.extend("Publication");
var publicationQuery = new Parse.Query(Publication);
publicationQuery.equalTo("user", currentUser);
publicationQuery.include("subCategory");
publicationQuery.find({
success: function(publications) {
console.log(publications[0].get("title"));
// This one returns undefined
console.log(publications[0].get("subCategory").get("name");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With