useGroupBy()

The useGroupBy method groups the collections items by a given key.


Usage

import { useRepo } from 'pinia-orm'import { useGroupBy } from 'pinia-orm/dist/helpers'import User from './models/User'const users = useRepo(User).all()// group by the 'name' attributeuseGroupBy(users, 'name')// group by the 'name' and 'age' attributeuseGroupBy(users, ['name', 'age'])

Type Declaration

export function useGroupBy<T>(models: T[], fields: string[] | string): Record<string, T[]>