Skip to content

Instantly share code, notes, and snippets.

@thebergamo
Created January 8, 2016 21:45
Show Gist options
  • Save thebergamo/e3215d3f9874e72e1906 to your computer and use it in GitHub Desktop.
Save thebergamo/e3215d3f9874e72e1906 to your computer and use it in GitHub Desktop.
'use strict';
module.exports = (sequelize, DataType) => {
let Category = sequelize.define('Category', {
name: {
type: DataType.STRING(100),
allowNull: false
},
description: {
type: DataType.TEXT,
allowNull: false,
defaultValue: ''
},
parentId: {
type: DataType.INTEGER,
allowNull: true,
references: {
model: 'Categories',
key: 'id'
}
},
status: {
type: DataType.BOOLEAN,
allowNull: false,
defaultValue: false
}
}, {
classMethods: {
associate: (models) => {
Category.belongsTo(models.Category, { foreignKey: 'parentId' });
Category.belongsToMany(models.Product,
{ through: 'ProductCategory' });
}
}
});
return Category;
};
'use strict';
module.exports = (sequelize, DataType) => {
let Product = sequelize.define('Product', {
name: {
type: DataType.STRING(100),
allowNull: false
},
description: {
type: DataType.TEXT,
allowNull: false,
defaultValue: ''
},
model: {
type: DataType.STRING(50),
allowNull: true
},
upc: {
type: DataType.STRING(13),
allowNull: true
},
price: {
type: DataType.DECIMAL(14, 2),
allowNull: false,
defaultValue: 0.00
},
status: {
type: DataType.BOOLEAN,
allowNull: false,
defaultValue: false
}
}, {
classMethods: {
associate: (models) => {
Product.belongsToMany(models.Category,
{ through: 'ProductCategory' });
}
}
});
return Product;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment