Merged PetitTeton webapp with the inventory tracking app; Moved the database configuration out of git and added an example configuration; Added migrations to the mix so that we can easily update the production database and roll back changes to the database (from the command line install migrations [may not be necessary?]:
npm install -g sequelize-cli To update the database after updating the app from git (on the command line in the webapp base directory): sequelize db:migrate To undo the last migrations: sequelize db:migrate:undo
This commit is contained in:
34
models/subcategory.js
Normal file
34
models/subcategory.js
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function(sequelize, DataTypes) {
|
||||
//The id field is auto added and made primary key.
|
||||
var Subcategory = sequelize.define('Subcategory', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
field: 'id',
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
field: 'name',
|
||||
allowNull: false
|
||||
},
|
||||
visible: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true
|
||||
}
|
||||
}, {
|
||||
freezeTableName: true, // Model tableName will be the same as the model name
|
||||
classMethods: {
|
||||
associate: function(models) {
|
||||
Subcategory.belongsTo(models.Category, {as: 'category', foreignKey: {name: 'categoryId', field: 'categoryId'}});
|
||||
Subcategory.hasMany(models.Item, {as: 'items', foreignKey: {name: 'subcategoryId', field: 'subcategoryId'}});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return Subcategory;
|
||||
};
|
||||
Reference in New Issue
Block a user