Typeorm: [Req] getManyCountAndRawMany

Created on 3 Feb 2017  路  3Comments  路  Source: typeorm/typeorm

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.

enhancement

Most helpful comment

i would use this

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NoNameProvided picture NoNameProvided  路  3Comments

idchlife picture idchlife  路  3Comments

leixu2txtek picture leixu2txtek  路  3Comments

cameronpickham picture cameronpickham  路  3Comments

crowebird picture crowebird  路  3Comments