1 import { model } from "@medusajs/framework/utils"
2 import ProductOption from "./product-option"
3 import ProductProductOption from "./product-product-option"
4 import ProductProductOptionValue from "./product-product-option-value"
5 import ProductVariant from "./product-variant"
6
7 const ProductOptionValue = model
8 .define("ProductOptionValue", {
9 id: model.id({ prefix: "optval" }).primaryKey(),
10 value: model.text().searchable().translatable(),
11 /**
12 * @since 2.16.0
13 */
14 rank: model.number().nullable(),
15 metadata: model.json().nullable(),
16 option: model
17 .belongsTo(() => ProductOption, {
18 mappedBy: "values",
19 })
20 .nullable(),
21 variants: model.manyToMany(() => ProductVariant, {
22 mappedBy: "options",
23 }),
24 /**
25 * @since 2.16.0
26 */
27 product_options: model.manyToMany(() => ProductProductOption, {
28 pivotEntity: () => ProductProductOptionValue,
29 mappedBy: "values",
30 }),
31 })
32 .indexes([
33 {
34 name: "IDX_option_value_option_id_unique",
35 on: ["option_id", "value"],
36 unique: true,
37 where: "deleted_at IS NULL",
38 },
39 ])
40
41 export default ProductOptionValue