Comments (4)
@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 Value
being a model. Instead, the property wrapper holds some type-erased properties (like _id: Any
) and then those properties are interpreted in extensions that know exactly what type the model is.
That way @Parent var galaxy: Galaxy
and @Parent var galaxy: Galaxy?
can have different storage and different methods. This is useful because the required relation's get
method should not return an optional. If it can't get the model for some reason, that should be an error. The second relation's get
method should return an optional though.
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.
from fluent-kit.
@OptionalParent
was added a while back. Closing this.
from fluent-kit.
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 RequiredParent
would be good for beginners, readability, or maintainability. I have no preference as to whether it's @Parent
with an optional property or @OptionalParent
.
from fluent-kit.
If we can't go with solution number four, I agree with @mcdappdev: it would be better to avoid @Required*
as I feel it would make the syntax "heavier" for what is probably going to be the most commonly used type of relation.
@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?
from fluent-kit.
Related Issues (20)
- Filtering with ~~ on enum collection does not work HOT 6
- Async functions within attach closure
- Aliases in select queries can cause fatal errors HOT 7
- Using Querybuilder with .field() or .fields() on models with optional relations crashes in SiblingsEagerLoader() HOT 1
- owner likely unsaved, attach within attach closure HOT 2
- [PostgreSQL] Storing Arrays of Custom Codable Types as JSONB[] instead of JSONB?
- Fluent Models malfunction if given a property named `description`
- @Group does not compile if SwiftUI is imported
- ServiceContext lost when eager loading parent models
- Fatal error "Non-uniform query input" when creating models from a collection. HOT 2
- Improve FieldKey ergonomics HOT 4
- Separate Field property wrappers into separate package HOT 4
- Print binding data in exception description
- Release 1.48.0 successfully blocks execution of method `try app.autoMigrate().wait()` HOT 9
- [Q]: Generic representation of a relationship
- Create on model collections does not assign database generated Ids HOT 4
- Can't query a single Field or the entire Group when querying a @Group modifier HOT 2
- Problem with filter on NULL (probably a Swift 6.0 bug) HOT 1
- Swift 6 `IS NOT NULL` where clause regression HOT 3
- Make `Database.logger` mutable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluent-kit.