tm-apps-db
Advanced tools
Comparing version 2.0.17 to 3.0.0
@@ -18,5 +18,5 @@ module.exports = { | ||
.then(() => { | ||
return queryInterface.removeColumn('article_sections', 'published_date', sequelize.DATE) | ||
return queryInterface.removeColumn('article_sections', 'published_date', sequelize.DATE); | ||
}); | ||
} | ||
}; |
@@ -88,4 +88,4 @@ "use strict"; | ||
associate: function(models) { | ||
article.belongsToMany(models.tag, {through: 'articles_tags', constraints: false}); | ||
article.belongsTo(models.section, {as: 'home_section', constraints: false}); | ||
article.hasMany(models.article_tag, {constraints: false}); | ||
article.hasMany(models.article_section, {constraints: false}); | ||
@@ -126,2 +126,9 @@ article.hasMany(models.article_content, {constraints: false}); | ||
}, | ||
purgeTags: function (options) { | ||
return sequelize.models.article_tag.destroy(R.merge({ where: {article_id: this.getDataValue('id')} }, options)); | ||
}, | ||
setTags: function (data, options) { | ||
const relations = R.map(R.assoc('article_id', this.getDataValue('id')), data); | ||
return sequelize.models.article_tag.bulkCreate(relations, options); | ||
}, | ||
findOrCreateThenSetTags: function (data, options) { | ||
@@ -128,0 +135,0 @@ const promises = R.map(tag => sequelize.models.tag.findOrCreate(R.merge(options, {where: { id: tag.id }, defaults: R.omit(['id'], tag)})).spread((a, b) => a), data); |
"use strict"; | ||
const R = require('ramda'); | ||
const utils = require('../utils'); | ||
@@ -11,2 +11,14 @@ module.exports = function(sequelize, DataTypes) { | ||
}, | ||
standardized_name: { | ||
type: DataTypes.STRING, | ||
allowNull: true | ||
}, | ||
tag_id: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
validate: { | ||
is: /^(regionals|nationals)\.[0-9]+$/ | ||
}, | ||
set: utils.idSetter | ||
}, | ||
name: { | ||
@@ -16,3 +28,6 @@ type: DataTypes.STRING, | ||
}, | ||
relevance: DataTypes.FLOAT | ||
article_count: { | ||
type: DataTypes.INTEGER, | ||
allowNull: true | ||
} | ||
}, { | ||
@@ -22,11 +37,13 @@ tableName: 'tags', | ||
classMethods: { | ||
associate: function (models) { | ||
tag.belongsToMany(models.article, { | ||
through: 'articles_tags', | ||
constraints: false | ||
}); | ||
associate: function(models) { | ||
tag.hasMany(models.article_tag, {constraints: false}); | ||
} | ||
} | ||
}, | ||
indexes: [ | ||
{ | ||
fields: ['tag_id'] | ||
} | ||
] | ||
}); | ||
return tag; | ||
}; |
{ | ||
"name": "tm-apps-db", | ||
"version": "2.0.17", | ||
"version": "3.0.0", | ||
"description": "Apps consumer database initialiser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
39841
39
1070