MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / groupBy

Method groupBy

packages/sql/src/query/QueryBuilder.ts:1843–1860  ·  view source on GitHub ↗
(fields: unknown)

Source from the content-addressed store, hash-verified

1841 fields: NestedAutoPath<Entity, RootAlias, Context, P> | readonly NestedAutoPath<Entity, RootAlias, Context, P>[],
1842 ): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
1843 groupBy(fields: unknown): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs> {
1844 this.ensureNotFinalized();
1845 this.#state.groupBy = Utils.asArray(
1846 fields as Field<Entity, RootAlias, Context> | readonly Field<Entity, RootAlias, Context>[],
1847 ).flatMap(f => {
1848 if (typeof f !== 'string') {
1849 // Normalize sql.ref('prop') to string for proper formula resolution
1850 if (isRaw(f) && f.sql === '??' && f.params.length === 1) {
1851 return this.resolveNestedPath(String(f.params[0]));
1852 }
1853
1854 return f;
1855 }
1856 return this.resolveNestedPath(f);
1857 }) as any;
1858
1859 return this as SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
1860 }
1861
1862 /**
1863 * Adds a HAVING clause to the query, typically used with GROUP BY.

Callers

nothing calls this directly

Calls 4

ensureNotFinalizedMethod · 0.95
resolveNestedPathMethod · 0.95
isRawFunction · 0.90
asArrayMethod · 0.80

Tested by

no test coverage detected