Code Monkey home page Code Monkey logo

Comments (4)

tanner0101 avatar tanner0101 commented on August 28, 2024 1

@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.

tanner0101 avatar tanner0101 commented on August 28, 2024 1

@OptionalParent was added a while back. Closing this.

from fluent-kit.

jdmcd avatar jdmcd commented on August 28, 2024

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.

PopFlamingo avatar PopFlamingo commented on August 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.