Hello, is there a way to rename grouped column nam...
# orm-help
k
Hello, is there a way to rename grouped column name:
Copy code
const { field } = params
const { priority, status } = query

const groups = await db.issue.groupBy({
	where: {
		priority: {
			in: priority,
		},
		status: {
			in: status,
		},
	},
	by: [field],
	_count: true,
	orderBy: {
		[field]: 'desc',
	},
})
return groups
returns
Copy code
[
	{
		"_count": 338,
		"status": "open"
	},
	{
		"_count": 312,
		"status": "in review"
	},
	{
		"_count": 359,
		"status": "in progress"
	},
	{
		"_count": 314,
		"status": "done"
	},
	{
		"_count": 366,
		"status": "canceled"
	},
	{
		"_count": 329,
		"status": null
	}
]
let's say to something generic like "status" -> "group"?
1
n
Hey 👋 Welcome to our Slack community! I think you could use Middleware to update the field name in the response returned by prisma.
k
Thank you! Interesting, I will have to look into that
l
You can also just map over the results in a `.then()`:
Copy code
return groups.map((d)=>({...d, group: d[field]}));
k
@Lloyd Richards thanks! that's what i ended up doing
👍 2