5.5.2. Data Model Property Types

In this chapter, you’ll learn about the types of properties in a data model’s schema.

These types are available as methods on the model utility imported from @medusajs/framework/utils.

id#

The id method defines an automatically generated string ID property. The generated ID is a unique string that has a mix of letters and numbers.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  id: model.id(),5  // ...6})7
8export default MyCustom

text#

The text method defines a string property.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  name: model.text(),5  // ...6})7
8export default MyCustom

number#

The number method defines a number property.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  age: model.number(),5  // ...6})7
8export default MyCustom

bigNumber#

The bigNumber method defines a number property that expects large numbers, such as prices.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  price: model.bigNumber(),5  // ...6})7
8export default MyCustom

boolean#

The boolean method defines a boolean property.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  hasAccount: model.boolean(),5  // ...6})7
8export default MyCustom

enum#

The enum method defines a property whose value can only be one of the specified values.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  color: model.enum(["black", "white"]),5  // ...6})7
8export default MyCustom

The enum method accepts an array of possible string values.


dateTime#

The dateTime method defines a timestamp property.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  date_of_birth: model.dateTime(),5  // ...6})7
8export default MyCustom

json#

The json method defines a property whose value is a stringified JSON object.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  metadata: model.json(),5  // ...6})7
8export default MyCustom

array#

The array method defines an array of strings property.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  names: model.array(),5  // ...6})7
8export default MyCustom

Properties Reference#

Refer to the Data Model API reference for a full reference of the properties.

Was this chapter helpful?
Edit this page