I have created several classes in parse and many of them are related to each other by Pointers. An example is the following.
I have 2 classes:
subcategorias
comercios
In comercios
I can have records from many businesses, there is a field called come_subc_id
and it is linked to the class subcategorias
by means of a Pointer.
In the class subcategorias
I have a classification of all businesses, that is, if it is a hotel, a restaurant, a laundry, etc.
I have one PFQueryTableViewController
where I intend to show a list of, for example, all the hotels.
If in my class subcategorias
, for example objectId
, the hotels class is gL8qGBhXMI
, how can I generate the query so that it only shows me in the table all the hotels that I have registered in the business class? My question is, how can I generate a query of a class by accessing the fields of another class through the pointer? I am trying as follows, but with errors and I have the following code and I still can't refine it and I don't know if I'm going in the right direction.
override func queryForTable() -> PFQuery {
let queryHot = PFQuery(className: "comercios") //El que funciona
queryHot.includeKey("come_subc_id") //Tipo pointer apuntando a clase subcategorias
queryHot.whereKey("come_subc_id", equalTo: "gL8qGBhXMI") // comparando si el registro tiene clasificacion de hotel
return queryHot
}
When I run the application, I get the following error:
2016-01-24 14:05:35.579 AppBeta1[1045:35017] [Error]: pointer field come_subc_id needs a pointer value (Code: 102, Version: 1.11.0)
I understand that the error is thrown in the query when I do the comparison:
queryHot.whereKey("come_subc_id", equalTo: "gL8qGBhXMI")
Since the field come_subc_id
is not of type string
but rather an object, my question is about how to implement the correct method to perform this comparison. If I manage to understand this part, I will be able to practically perform all the queries that are generated in my application since all the classes are related by pointers.
If I have not been completely clear, I can restate my problem.
Thank you for your support.
Something similar happened to me but using JavaScript, apparently Parse does not accept that you pass strings as Pointers, you have to pass an object.
The solution is that when doing the query, you use an object in the part of the
equalTo
. I don't know anything about Swift but, with the help of the documentation, I suppose that something like this could work:I hope the code is correct but the idea is similar to the answer that was given to me in my question How to query a Pointer field with the ID of the object? .
Thank you very much Cesar Bustios for the guide.
Indeed I had to adapt it for swift and it ended up like this:
It has worked!!!