-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
optional relations #62
Comments
I think that all relations should be required by default, with the ability to specify an optional variant. I do not think that making all relations optional or even requiring something like |
If we can't go with solution number four, I agree with @mcdappdev: it would be better to avoid @tanner0101 When you say it's not clear wether or not 4) is makable, what are the main issues you are seeing? From what I just tried it's not possible to overload the property warper init so it seems like a dynamic cast is required, is this about performance you are worried? |
@adtrevor I was thinking something like this: @propertyWrapper
final class Parent<Value> {
var _id: Any
init(key: String) { ... }
}
extension Parent where Value: Model {
var id: Value.ID {
...
}
func get(on database: Database) -> EventLoopFuture<Value> {
...
}
}
extension Parent where Value: OptionalType, Value.Wrapped: Model {
var id: Value.Wrapped.ID {
...
}
func get(on database: Database) -> EventLoopFuture<Value.Wrapped?> {
...
}
} The idea here is that the property wrappers don't have a hard requirement on the That way However, as you said, this could get weird with init method overloads and stuff. I can't be sure whether or not this would work until I or someone else tries it. |
|
@Parent
,@Children
, and@Siblings
should support optional relations.Some ways to achieve this are:
1: Make all relations optional
2: Make all relations optional and provide
@Required*
versions, i.e.,@RequiredParent
3: Make all relations required and provide
@Optional*
versions, i.e.,@OptionalParent
4: Allow relations to be declared as optional / required on individual basis, i.e.:
The text was updated successfully, but these errors were encountered: