3.4.2. Data Model Property Types

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

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

float#

NoteThis property is only available after Medusa v2.1.2.

The float method defines a number property that allows for values with decimal places.

TipUse this property type when it's less important to have high precision for numbers with large decimal places. Alternatively, for higher percision, use the bigNumber property.

For example:

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

bigNumber#

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

TipUse this property type when it's important to have high precision for numbers with large decimal places. Alternatively, for less percision, use the float property.

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