-
-
Notifications
You must be signed in to change notification settings - Fork 502
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
Using EntityManager.map() with Query Builder #1660
Comments
Why don't use use
Lastly, https://github.com/mikro-orm/mikro-orm/blob/master/packages/core/src/EntityManager.ts#L484 |
Interesting, I'll have a look. Thanks! |
Yup, much simpler. I'm not sure how I missed We're still depending on |
Maybe we could move the |
Yup, that'd work well I think. Do you want me to explore a PR that does that? |
Sure, feel free to give it a try. Should be just about moving the logic inside QB ( |
Yup, cool, I'll give it a try. |
It's a bit too tangled up to pull it into the query builder I think. In this.joinedProps(meta, populate); If we move this into QueryBuilder, then a bunch of tests (like I think it'd make more sense to expose a method on the query builder called Does that make sense and sound like a good idea? In other words, leave things how they are, but also add a way for users to explicitly ask QueryBuilder to do the auto join, leaving the logic in the AbstractSQLDriver. |
But |
|
Is your feature request related to a problem? Please describe.
We're using QueryBuilder because we need some relatively complex join logic. What we'd like is to be able to take this query, then load entities from it. We are using EntityManager.map() but hit two things with it that I'm not sure are meant to be supported or not, so I'm assuming it's a feature request.
Describe the solution you'd like
We'd like to be able to await query builder's
execute()
thenEntityManager.map()
to get entities back. Our current implementation (which we think we can improve) is:We're needing to do more than just a call to
.map
for three reasons:.map
with the raw query builder result, we get an error converting numbers to strings.driver.mapResult
fixes this, but then we need to grab the metadata for the entity to do that process.@OneToOne
relationships, so are currently using theautoJoinOneToOneOwner
helper, but we can see this isn't meant to be part of the API.driver.mapResult
is typed so that it can return null, whichEntityManager.map
does not accept, hence the|| {}
that we know won't actually be used here, this is just to get TypeScript to calm down.Describe alternatives you've considered
Continue with this implementation as is, because it works fine for the moment. Not ideal as it's quite tightly coupled to Mikro internals, but would be absolutely fine.
Additional context
driver.mapResult
should happen withinEntityManager.map
itself. If map is meant to take a raw database result from a query builder then this is a step that we should probably do within.map
, no?@OneToOne
front, it feels like we're probably going about this the wrong way. Is there a supported API way to tell a query builder to do these joins before we runexecute()
? If not, should there be for this use case? Should this method become public?As always, happy to do the PR to make
.map
easier to use, just wondering about the intended developer experience here and if we're just using it wrong.The text was updated successfully, but these errors were encountered: