mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 03:29:37 +02:00
Category model and controllers
This commit is contained in:
parent
5c948e1a68
commit
100f274d96
8 changed files with 164 additions and 4 deletions
21
models/Bookmark.js
Normal file
21
models/Bookmark.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../db');
|
||||
|
||||
const Bookmark = sequelize.define('Bookmark', {
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
url: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
categoryId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'bookmarks'
|
||||
});
|
||||
|
||||
module.exports = Bookmark;
|
17
models/Category.js
Normal file
17
models/Category.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../db');
|
||||
|
||||
const Category = sequelize.define('Category', {
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
isPinned: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'categories'
|
||||
});
|
||||
|
||||
module.exports = Category;
|
13
models/associateModels.js
Normal file
13
models/associateModels.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const Category = require('./Category');
|
||||
const Bookmark = require('./Bookmark');
|
||||
|
||||
const associateModels = () => {
|
||||
// Category <> Bookmark
|
||||
Bookmark.belongsTo(Category, { foreignKey: 'categoryId' });
|
||||
Category.hasMany(Bookmark, {
|
||||
as: 'bookmarks',
|
||||
foreignKey: 'categoryId'
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = associateModels;
|
Loading…
Add table
Add a link
Reference in a new issue