-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Setting property to nil doesn't save to database #264
Comments
Thanks for opening this issue!
|
The Swift SDK uses a tailored JSONEncoder. The Apple
The easiest way to achieve what you are looking for is by using var testObj = TestObject()
let operations = testObj.operation.unset("testValue") // Unset on the server
testObj = try await operations.save()
// or unset on the server and on the local ParseObject
let operations = testObj.operation.unset(("testValue", \.testValue))
testObj = try await operations.save()
// or unset multiple during the same save on the server and locally
let operations = testObj.operation
.unset(("testValue", \.testValue))
.unset(("testValue2", \.testValue2))
testObj = try await operations.save() If you need to access the custom ParseEncoder, see the post here: https://community.parseplatform.org/t/parsefile-init-without-previous-fetch/1666/6?u=cbaker6 You can also access the encoders using a static |
I see. Given the movement in that Swift thread, it doesn't seem like this is going to be addressed by the Swift Encoder any time soon. It does seem like this would be expected behavior for the SDK, given the behavior of other Parse SDKs and setting nil values. Unset works but we do have situations in some cases where values drop to nil without necessarily being explicitly unset. The NullEncodable property wrapper referenced in that Stack Overflow question looks interesting, seems like it would handle the situation properly as long as optional model properties had this wrapper attached to it. How do you feel about including an implementation of this in the ParseSwift SDK and then including in the documentation instructions on using it for optional values? Realm SDK model objects use property wrappers quite a bit and it's a fairly easily understood process so I don't think that's out of the ordinary, and then it would clarify in the sample model objects that optional values need this wrapper - we weren't aware that the SDK didn't do this already and it caused some bugs when we transitioned from the Objective C SDK to this one on one of our projects. |
maybe, if you are willing to work on a PR with testcases and it doesn’t break the current testcases, I can review it |
It seems another approach a developer can take is simply add the dependency via SPM, https://github.com/g-mark/NullCodable and then use the wrapper on your property. struct TestObject: ParseObject {
// ParseObject Conformance
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
@NullCodable var testValue: String?
}
var testObj = TestObject()
testObj.testValue = "value" // Set
testObj = try await testObj.save()
testObj.testValue = nil // Unset
testObj = try await testObj.save() or you can use ParseOperation, #264 (comment) |
So I ran into a problem, and it ties into discussion being had over in #242 and #263. This is incompatible with If the work in #263 does end up getting merged, I can likely use that to compare and then only unset properties that were explicitly unset, but I do feel weary about the SDK having implicit persistence. I'll probably jump in on that PR as well. I think some of these features are very important, but a cache might end up being quite fragile. |
The label |
Anyone coming across this issue should see my answer here: #268 (comment) |
Closing this due to no activity and the previous answers providing the capability |
New Issue Checklist
Issue Description
Setting a value on an optional model property doesn't propagate to the server.
Steps to reproduce
Expected Outcome
Final value on dashboard should be (undefined) or nil, instead of keeping the old value.
Environment
Client
2.0.2
13.0
macOS
11.6
Server
4.10.4
Ubuntu
Digital Ocean
Database
MongoDB
4.4
Digital Ocean
The text was updated successfully, but these errors were encountered: