我正在尝试使用Sequelize将产品添加到我的postgresql数据库中。在弄清楚如何在表模型定义中将自定义数据类型“ product”作为数组包括在内时,我遇到了一些困难。
模型定义:
const Product = sequelize.define('product', {
product_category: Sequelize.TEXT,
product_id: Sequelize.TEXT,
product_name: Sequelize.TEXT,
product_image: Sequelize.TEXT,
});
const Orders = sequelize.define('orders', {
order_id: Sequelize.TEXT,
products: Sequelize.ARRAY(Sequelize.Product),
}, {
freezeTableName: true,
});
我的表定义:
CREATE TABLE orders (
order_id text PRIMARY KEY,
products product[]
);
我的自定义类型定义:
CREATE TYPE product AS (
product_category TEXT,
product_id TEXT,
product_name TEXT,
product_image TEXT
);