-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.select() in finds and firsts does not seem to exclude any fields #86
Comments
I could be wrong, but I think this test may be incorrectly written:
I would imagine it could be something like:
|
What error are you getting when trying select? |
The test looks okay from what I see. An improvement could be to check that the selected keys are encoded because if Parse-Swift/Tests/ParseSwiftTests/ParseQueryTests.swift Lines 595 to 619 in 65bfd41
There's no need to actually perform the query as 1) you will need to mock the network (like some of the other tests) 2) Testing to see if the keys array is populated/encoded properly is good enough for a client side test since the Parse Server does the rest. |
If you add an example in Playgrounds to https://github.com/parse-community/Parse-Swift/blob/main/ParseSwift.playground/Pages/2%20-%20Finding%20Objects.xcplaygroundpage/Contents.swift I can take a look |
I've tested this by adding to the playgrounds file struct GameScore: ParseObject {
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Int?
var oldScore: Int?
}
var score = GameScore()
score.score = 200
score.oldScore = 10
do {
try score.save()
} catch {
print(error)
}
let afterDate = Date().addingTimeInterval(-300)
var query = GameScore.query("score" > 100, "createdAt" > afterDate)
// Query first asynchronously (preferred way) - Performs work on background
// queue and returns to designated on designated callbackQueue.
// If no callbackQueue is specified it returns to main queue.
query.first { results in
switch results {
case .success(let score):
guard score.objectId != nil,
let createdAt = score.createdAt else { fatalError() }
assert(createdAt.timeIntervalSince1970 > afterDate.timeIntervalSince1970, "date should be ok")
print("Found score: \(score)")
case .failure(let error):
assertionFailure("Error querying: \(error)")
}
}
//The above outputs:
// Found score: GameScore ({"objectId":"oBdHL84zSZ9qCWXFrB4RkhR5AOJd0a5U","updatedAt":{"__type":"Date","iso":"2021-03-02T18:30:07.596Z"},"score":200,"createdAt":{"__type":"Date","iso":"2021-03-02T18:30:07.482Z"}})
let querySelect = query.select("score")
querySelect.first { results in
switch results {
case .success(let score):
guard score.objectId != nil,
let createdAt = score.createdAt else { fatalError() }
assert(createdAt.timeIntervalSince1970 > afterDate.timeIntervalSince1970, "date should be ok")
print("Found score using select: \(score)")
case .failure(let error):
assertionFailure("Error querying: \(error)")
}
}
//Outputs:
//Found score using select: GameScore ({"objectId":"oBdHL84zSZ9qCWXFrB4RkhR5AOJd0a5U","updatedAt":{"__type":"Date","iso":"2021-03-02T18:30:07.596Z"},"score":200,"createdAt":{"__type":"Date","iso":"2021-03-02T18:30:07.482Z"}})
|
Note that if you add a property to the your type that isn't optional (added struct GameScore: ParseObject {
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Int?
var oldScore: Int?
var highestScore: Int //New property
}
|
There may be something up with this... |
Thanks @cbaker6 Glad it's working! I can't seem to reproduce your results, so I'll play around and see if I'm bugging out.
No error, but I'm getting all the fields back.
Agree. EDIT: I'm using Parse-Swift 1.1.6 and Parse-Server 4.5.0. |
The fix on the server side has been merged to the master. If you would like to use |
Hey @cbaker6 - Do you think this could be an encoding problem or a potential parse-server bug?
Anybody have any thoughts? Will dig deeper into the source, if not. Thanks!
EDIT:
.select() does seem to work, as of late. Reference: https://stackoverflow.com/questions/61100282/parse-server-select-a-few-fields-from-included-object
The text was updated successfully, but these errors were encountered: