Is it possible to return both mapped entity as well as the raw result from the same query?
In query like this:
let item = await ItemRepository
.createQueryBuilder("variant")
.addSelect("COUNT(variant.result) AS vote")
.groupBy("variant.model_id")
.setFirstResult(0)
.setMaxResults(20)
.getRawMany();
Because of the extra addSelect
field, I can't use getManyAndCount()
because the vote
values won't be mapped to the entity. I have to set the entire data to the class property manually, which is pretty painful if the query is complicated.
But if we have functions like getManyAndRawManyAndCount()
I can loop the mapped result and set the vote
values from the raw result relatively easily.
I missed the getEntitiesAndRawResults
, which is what I have been looking for, but is it possible to get the count result from getManyAndCount
as well?
I don't think its good to create extra getManyCountAndRawMany
method in query builder. Not sure how many people except you gonna use it. So, please use getCount
method together with other methods you need.
i would use this
Most helpful comment
i would use this