I'm trying to get the fields of a Pointer
in the way suggested in this post but it always returns undefined
.
Table Publication
:
userId
->User
subCategoryId
->Subcategory
title
description
budget
Table SubCategory
:
categoryId
->Category
name
isActive
And this is the code I'm trying (I only have one record in 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"));
// Me retorna undefined
console.log(publications[0].get("subCategoryId"));
}
});
What I need to do is:
publications[0].get("subCategoryId").get("name");
But the above obviously returns me:
Uncaught TypeError: Cannot read property 'get' of undefined
Cross-post on Stack Overflow
If you have pointers in your parsing database like the following, there's no need to work with ObjectIDs.
The data you should have is something like this:
Publication:
Pointer <_User>
)Pointer <SubCategory>
)String
)String
)SubCategory:
Pointer <Category>
)String
)boolean
)So if you are saving data as expected the following should work:
Original answer https://stackoverflow.com/questions/34734070/retrieving-information-from-pointer-field/34734320#34734320