1 import { model } from "@medusajs/framework/utils"
2 import Customer from "./customer"
3 import { CustomerGroupCustomer } from "@models"
4
5 const CustomerGroup = model
6 .define("CustomerGroup", {
7 id: model.id({ prefix: "cusgroup" }).primaryKey(),
8 name: model.text().searchable().translatable(),
9 metadata: model.json().nullable(),
10 created_by: model.text().nullable(),
11 customers: model.manyToMany(() => Customer, {
12 mappedBy: "groups",
13 pivotEntity: () => CustomerGroupCustomer,
14 }),
15 })
16 .indexes([
17 {
18 on: ["name"],
19 unique: true,
20 where: "deleted_at IS NULL",
21 },
22 ])
23 .cascades({
24 detach: ["customers"],
25 })
26
27 export default CustomerGroup