Code Monkey home page Code Monkey logo

Comments (7)

B4nan avatar B4nan commented on June 24, 2024 1

Nope, without using the Ref wrapper, there is no difference between a populated and not populated relation property (on type level), without that the assignability cannot work properly - its not about comparing the populate hint, its about assignability of what the Loaded type resolves.

from mikro-orm.

B4nan avatar B4nan commented on June 24, 2024 1

It would be technically possible to make this work without the Ref wrapper, but it would be quite a breaking change. It's not just about the assignability of the Loaded type itself in explicit hints, it would affect the assignability of relations in general.

Maybe something to think about when I start thinking about v7 (next year+).

from mikro-orm.

B4nan avatar B4nan commented on June 24, 2024

You need to use the Ref wrapper on the M:1 properties, otherwise this cannot work.

from mikro-orm.

kpervin avatar kpervin commented on June 24, 2024

Alright, glad to know that's the issue. I figured that was likely the case, as it was resolved as soon as I added the Ref attribute. That being said, the types still don't match so therefore it should throw an error, no? Because it errors as expected if you only add the non-ref M:1 relations into the populate array, but as soon as you add the posts collection in there, it seems to resolve fine.

from mikro-orm.

kpervin avatar kpervin commented on June 24, 2024

Well I have a lot of refactoring to do it seems given we did not use the Ref property in the beginning...

from mikro-orm.

kpervin avatar kpervin commented on June 24, 2024

Not sure if it's worth it, tbh. It's kind of in the name: Type-Safe relations :P

from mikro-orm.

kpervin avatar kpervin commented on June 24, 2024

On second thought, it would be nice to have relations loaded via populate and it affects the returned value, where any omitted values from the populate array is simply omitted from the returned entity type not unlike Prisma. That would possibly eliminate the need for the Ref type in its entirety. It would be a fundamental change however, but what are your thoughts on that? Possibly a means to do so would require that every entity extends BaseEntity at least to some degree to pick up that it is an entity type. The Ref type could be then be relegated to only situations of lazy-loading (possibly renamed to Lazy or something).

from mikro-orm.

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.