-
-
Notifications
You must be signed in to change notification settings - Fork 69
feat: improve ParseRelation and ParseRole #328
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
Conversation
Thanks for opening this pull request!
|
Codecov Report
@@ Coverage Diff @@
## main #328 +/- ##
==========================================
+ Coverage 85.02% 85.11% +0.08%
==========================================
Files 114 114
Lines 12048 12116 +68
==========================================
+ Hits 10244 10312 +68
Misses 1804 1804
Continue to review full report at Codecov.
|
|
@jaysonng you can track this PR for adjustments. Note that though this will improve the ability of a |
yessir! I've been working with ParseRelation the past couple of days and this PR will be a big help. You rock! |
|
Linking this current example as the earlier one posted above links to an older revision of ParseRole. Current way to use computed property ParseRelation needs try? Parse-Swift/Sources/ParseSwift/Objects/ParseRole.swift Lines 79 to 85 in 96232f3
If you can update your message above @cbaker6, I'll just remove this one as later. thanks, |
New Pull Request Checklist
Issue Description
Currently a
ParseRelationisn'tDecodable. This is because decoding aParseRelationdoesn't yield a "usable"ParseRelationout-of-the-box.See discussion here: #294 (comment)
Related issue: #n/a
Approach
Make
ParseRelationconform toCodableand add methods to make decoded storedParseRelations "usable".ParseObjects can now contain properties of ParseRelation. In addition,ParseRelations can now be made fromParseObjectpointers. Also removed the need to specify the child object for aParseRelationquery as this can be type inferred by the developer.Breaking Changes to both
ParseRelationandParseRole. For ParseRole, the computed properties: users and roles, are now optional. The queryRoles property has been changed to queryRoles() to improve the handling of thrown errorsNote the improvements of this PR are possible because of the requirements made in
4.0.0which require allParseObject's to have aninit(); giving flexibility back to the SDK by enabling it to initializeParseObject's internally. For example, previously when creating aParseObject, the SDK can only convert:ParseObject->Pointer<ParseObject>, but not reverse this conversion. Since an object can be initialized, the SDK can now reverse the aforementioned conversion:Pointer<ParseObject>->ParseObject. See more here: #315 (comment)The best way still to use
ParseRelationis by using computed properties which is available in older and newer versions of the Swift SDK. An example of creatingParseRelation's that are computed properties (these are usable out-of-the-box) are theusersandrolesinParseRole:>= 4.0.0:Parse-Swift/Sources/ParseSwift/Objects/ParseRole.swift
Lines 79 to 85 in 96232f3
< 4.0.0:Parse-Swift/Sources/ParseSwift/Objects/ParseRole.swift
Lines 99 to 117 in c119033
and then querying the relations by using the methods available on the returned computed property.
For stored
ParseRelation's (those decoded from the ParseServer), the "computed property" mentioned earlier still works the best, assuming you now how to construct theParseRelationwithout the server. If you need to make a storedParseRelation"usable", the following methods have been added to allParseObect's in this PR:/** Establish a relation based on a stored relation. - parameter relation: The stored relation property. - parameter key: The key for the relation. - parameter with: The parent `ParseObject` Pointer of the `ParseRelation`. - returns: A usable `ParseRelation` based on the stored relation property. */ static func relation<T: ParseObject>(_ relation: ParseRelation<T>?, key: String, with parent: Pointer<T>) throws -> ParseRelation<T> /** Establish a relation based on a stored relation. - parameter relation: The stored relation property. - parameter key: The key for the relation. - parameter with: The parent `ParseObject` of the `ParseRelation`. - returns: A usable `ParseRelation` based on the stored relation property. */ static func relation<T: ParseObject>(_ relation: ParseRelation<T>?, key: String, with parent: T) throws -> ParseRelation<T> /** Establish a relation based on a stored relation with this `ParseObject` as the parent. - parameter relation: The stored relation property. - parameter key: The key for the relation. - returns: A usable `ParseRelation` based on the stored relation property. */ func relation(_ relation: ParseRelation<Self>?, key: String) throws -> ParseRelation<Self> /** Establish a relation based on a stored relation. - parameter relation: The stored relation property. - parameter key: The key for the relation. - parameter with: The parent `ParseObject` of the `ParseRelation`. - returns: A usable `ParseRelation` based on the stored relation property. */ func relation<T: ParseObject>(_ relation: ParseRelation<T>?, key: String, with parent: T) throws -> ParseRelation<T> /** Establish a relation based on a stored relation. - parameter relation: The stored relation property. - parameter key: The key for the relation. - parameter with: The parent `ParseObject` Pointer of the `ParseRelation`. - returns: A usable `ParseRelation` based on the stored relation property. */ func relation<T: ParseObject>(_ relation: ParseRelation<T>?, key: String, with parent: Pointer<T>) throws -> ParseRelation<T>An example of using one of the new methods is in the Playgrounds. They are all similar. Assuming you have the
var scores: ParseRelation<Self>?as one of your stored properties ofUser:Parse-Swift/ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift
Lines 16 to 44 in ea631f5
You can make
scoresusable by doing the following (it's actually a lot cleaner if you useguard, but Playgrounds only allowsguardinside of closures because of it's structure:Parse-Swift/ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift
Lines 353 to 379 in ea631f5
TODOs before merging