|
1
|
import { model } from "@medusajs/framework/utils" |
|
2
|
import Region from "./region" |
|
3
|
|
|
4
|
export default model |
|
5
|
.define( |
|
6
|
{ name: "Country", tableName: "region_country" }, |
|
7
|
{ |
|
8
|
iso_2: model.text().searchable().primaryKey(), |
|
9
|
iso_3: model.text(), |
|
10
|
num_code: model.text(), |
|
11
|
name: model.text().searchable(), |
|
12
|
display_name: model.text(), |
|
13
|
region: model |
|
14
|
.belongsTo(() => Region, { mappedBy: "countries" }) |
|
15
|
.nullable(), |
|
16
|
metadata: model.json().nullable(), |
|
17
|
} |
|
18
|
) |
|
19
|
.indexes([ |
|
20
|
{ |
|
21
|
// TODO: Remove ts-ignore when field inference takes into account the nullable property |
|
22
|
// @ts-ignore |
|
23
|
on: ["region_id", "iso_2"], |
|
24
|
unique: true, |
|
25
|
}, |
|
26
|
]) |