Hi, I have a class :
class BidHistory : NSObject {
var objectId: String?
var userObjectID: String?
var bidParticipatedIn: BidItem?
var bidStatusDescription: NSNumber? = 111
}
I want to search in the dataBase a BidHistory object by the bidParticipatedIn object… I get an error like :
FAULT = ‘Server.Processing’ [java.lang.RuntimeException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1] <java.lang.RuntimeException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1>
I attached a screenshot with my request.
Thank you!
I want to do it optimally…for now what I do is this :
static func getBidHistoryByBidItem(userObjectId: String, bidItem: BidItem?, completionHandler: BidHistory? -> Void ) {
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = "userObjectID = '\(userObjectId)'"
Backendless.sharedInstance().data.of(BidHistory.ofClass()).find(dataQuery, response: { (collectionObjects) in
if let data = collectionObjects.data {
let bidHistoryObjects = data as! [BidHistory]
for i in 0..<bidHistoryObjects.count {
let aBidHistory = bidHistoryObjects as BidHistory
if aBidHistory.bidParticipatedIn?.objectId == bidItem?.objectId {
completionHandler(aBidHistory)
return
}
}
completionHandler(nil)
}
}) { (fault) in
print("There was an error on retrieving the bid history for the current user: \(fault)")
}
}
Isabela, you could do it more optimally with
dataQuery.whereClause = "userObjectID = '\(userObjectId)' AND bidParticipatedIn.objectId = '\(bidItem!.objectId)'"
Please investigate this and this docs.
And please remove (or rename) ‘description’ field in Users table: it throws an exception.
Ok, I removed it. Thank you!