I have a state
where I'm passing the ID of my class Category
:
.state('app.create-chambba', {
cache: false,
url: "/services/create-chambba/:categoryId",
views: {
"menuContent": {
templateUrl: "views/app/services/create_chambba.html",
controller: "CreateChambbaCtrl"
}
}
})
The thing is, in my controller CreateChambbaCtrl
I thought I could use the categoryId
to get all the sub-categories that belong to that category. Something like that:
var SubCategory = Parse.Object.extend("SubCategory");
var query = new Parse.Query(SubCategory);
query.equalTo("isActive", true);
query.equalTo("categoryId", $stateParams.categoryId); // El ID de categoría
query.ascending("name");
query.find(...);
But doing it that way returns the following error:
message: "pointer field categoryId needs a pointer value"
So, I decided to first query the category to get the object and then with that object get the sub-categories:
var Category = Parse.Object.extend("Category");
var queryCategory = new Parse.Query(Category);
queryCategory.equalTo("objectId", $stateParams.categoryId);
queryCategory.first({
success: function(category) {
var SubCategory = Parse.Object.extend("SubCategory");
var query = new Parse.Query(SubCategory);
query.equalTo("isActive", true);
query.equalTo("categoryId", category);
query.ascending("name");
query.find(..);
}
});
Somehow I feel like I'm doing extra work, is there a better way?
Cross-post on Stack Overflow
Alon 's answer in the Stack Overflow cross-post
Create a new object from
Category
and set the object's ID to the ID you want to search for:And use the object as a
Pointer
:It's a little hack but it should solve your problem.