|
1
|
import { model } from "@medusajs/framework/utils" |
|
2
|
import Product from "./product" |
|
3
|
import ProductVariant from "./product-variant" |
|
4
|
import ProductVariantProductImage from "./product-variant-product-image" |
|
5
|
|
|
6
|
const ProductImage = model |
|
7
|
.define( |
|
8
|
{ tableName: "image", name: "ProductImage" }, |
|
9
|
{ |
|
10
|
id: model.id({ prefix: "img" }).primaryKey(), |
|
11
|
url: model.text(), |
|
12
|
metadata: model.json().nullable(), |
|
13
|
rank: model.number().default(0), |
|
14
|
product: model.belongsTo(() => Product, { |
|
15
|
mappedBy: "images", |
|
16
|
}), |
|
17
|
/** |
|
18
|
* @since 2.11.2 |
|
19
|
*/ |
|
20
|
variants: model.manyToMany(() => ProductVariant, { |
|
21
|
mappedBy: "images", |
|
22
|
pivotEntity: () => ProductVariantProductImage, |
|
23
|
}), |
|
24
|
} |
|
25
|
) |
|
26
|
.indexes([ |
|
27
|
{ |
|
28
|
name: "IDX_product_image_url", |
|
29
|
on: ["url"], |
|
30
|
unique: false, |
|
31
|
where: "deleted_at IS NULL", |
|
32
|
}, |
|
33
|
{ |
|
34
|
name: "IDX_product_image_rank", |
|
35
|
on: ["rank"], |
|
36
|
unique: false, |
|
37
|
where: "deleted_at IS NULL", |
|
38
|
}, |
|
39
|
{ |
|
40
|
name: "IDX_product_image_url_rank_product_id", |
|
41
|
on: ["url", "rank", "product_id"], |
|
42
|
unique: false, |
|
43
|
where: "deleted_at IS NULL", |
|
44
|
}, |
|
45
|
{ |
|
46
|
name: "IDX_product_image_rank_product_id", |
|
47
|
on: ["rank", "product_id"], |
|
48
|
unique: false, |
|
49
|
where: "deleted_at IS NULL", |
|
50
|
}, |
|
51
|
]) |
|
52
|
|
|
53
|
export default ProductImage |