-
-
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
feat: improve ParseRelation by adding more methods #294
Conversation
Thanks for opening this pull request!
|
Codecov Report
@@ Coverage Diff @@
## main #294 +/- ##
==========================================
+ Coverage 82.36% 82.70% +0.34%
==========================================
Files 104 104
Lines 10659 10638 -21
==========================================
+ Hits 8779 8798 +19
+ Misses 1880 1840 -40
Continue to review full report at Codecov.
|
I was wondering what the reason was for changing ParseRelation protocol from Codable to Encodable? (Removing Decodable?) I'm asking because I now have to implement custom init(from:) for my ParseObjects which has a ParseRelation object nested inside them, when I didn't have to before. Should I not be decoding relations objects? For context, I add Codable to an object of mine for saving in UserDefaults. also, if this is not the right place to ask this, I can re-ask this in the forums. |
What’s the usecase for decoding a ParseRelation? You currently can’t fetch this type from the server, why would you fetch it from storage? |
In may case, I store a Location object in UserDefaults. (so I have a default Location loaded up in the app without having to wait and find the device current location or have the user select a location.) The Location object has 2 ParseRelation properties to 2 other ParseObjects -> Tags and Images. I can do away saving the images in UserDefaults as they will be huge, but Tags might be something I want stored as well. |
A Parse-Swift/Sources/ParseSwift/Types/ParseRelation.swift Lines 66 to 69 in b92667f
This means that even if you decoded a struct StoredParseRelation: Decodable {
var className: String
// Call this function to get a working ParseRelation on an instance of the struct.
func createParseRelation<T: ParseObject>(_ parent: T, key: String) -> ParseRelation<T> {
ParseRelation(parent: parent, key: key, className: className)
}
} |
I'll rework my code to get this working. and no, I haven't been able to get to the part of actually checking the ParseRelation objects in my ParseObject before but all these errors popped up when I updated my ParseSwift to 3.1.0 so I had to tackle them now. :) Thank you once again! I think I understand this more now. |
@cbaker6 , a follow up question, Should we never place ParseRelation properties in structs? So whenever a struct that has a ParseRelation, I get the "does not conform to protocol 'Decodable' error. It seems like we don't really need to have ParseRelation properties in the struct do we? (Even if the relation is in the Parse database). Was the intention of ParseRelation not be part of the struct object itself? From what I understand, I don't access that property at all when I want to query relations anyway right? Otherwise I'd need to be implementing init(from:) on all objects with ParseRelations. Thank you very much! |
An encoded ParseRelation doesn’t have enough info to be useful when decoding. Instead, you should be saving and querying the relation like the example in the Playgrounds: Parse-Swift/ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift Lines 281 to 343 in c119033
I’ll look into adding ParseRelation as decodable for version 4.0.0, but my guess is you will still need to pass the string name of the property and access it similar to the Playgrounds as it can’t be used by itself. You typically want to create computed properties for your Parse-Swift/Sources/ParseSwift/Objects/ParseRole.swift Lines 99 to 117 in c119033
|
New Pull Request Checklist
Issue Description
ParseRelation
can use some additional methods to make it easier to create and query relations.Related issue: #n/a
Approach
Add the following:
ParseRelation
:func add<U>(_ objects: [U]) throws -> ParseOperation<T> where U: ParseObject
ParseRelation
:func remove<U>(_ objects: [U]) throws -> ParseOperation<T> where U: ParseObject
ParseRelation
:func query<U>(_ key: String, parent: U) throws -> Query<T> where U: ParseObject
ParseRelation
:func query<U>(_ key: String, child: U) throws -> Query<U> where U: ParseObject
ParseRelation
Playground save/query exampleQueryConstraint
:func related(key: String) -> QueryConstraint
QueryConstraint
:func related <T>(object: T) throws -> QueryConstraint where T: ParseObject
QueryConstraint
:func related <T>(object: Pointer<T>) -> QueryConstraint where T: ParseObject
Removed the following:
ParseOperation
andParseRelation
to get rid of unnecessary unwrappingTODOs before merging