Migrate atlasId -> collectionId
This commit is contained in:
@ -119,7 +119,7 @@ const Document = sequelize.define(
|
||||
Document.associate = models => {
|
||||
Document.belongsTo(models.Collection, {
|
||||
as: 'collection',
|
||||
foreignKey: 'atlasId',
|
||||
foreignKey: 'collectionId',
|
||||
onDelete: 'cascade',
|
||||
});
|
||||
Document.belongsTo(models.Team, {
|
||||
@ -266,7 +266,7 @@ Document.searchForUser = async (
|
||||
Document.addHook('beforeSave', async model => {
|
||||
if (!model.publishedAt) return;
|
||||
|
||||
const collection = await Collection.findById(model.atlasId);
|
||||
const collection = await Collection.findById(model.collectionId);
|
||||
if (collection.type !== 'atlas') return;
|
||||
|
||||
await collection.updateDocument(model);
|
||||
@ -276,7 +276,7 @@ Document.addHook('beforeSave', async model => {
|
||||
Document.addHook('afterCreate', async model => {
|
||||
if (!model.publishedAt) return;
|
||||
|
||||
const collection = await Collection.findById(model.atlasId);
|
||||
const collection = await Collection.findById(model.collectionId);
|
||||
if (collection.type !== 'atlas') return;
|
||||
|
||||
await collection.addDocumentToStructure(model);
|
||||
@ -295,7 +295,7 @@ Document.addHook('afterDestroy', model =>
|
||||
Document.prototype.publish = async function() {
|
||||
if (this.publishedAt) return this.save();
|
||||
|
||||
const collection = await Collection.findById(this.atlasId);
|
||||
const collection = await Collection.findById(this.collectionId);
|
||||
if (collection.type !== 'atlas') return this.save();
|
||||
|
||||
await collection.addDocumentToStructure(this);
|
||||
|
Reference in New Issue
Block a user