fix: Deeply nested document titles not updated in collection documentStructure cache
closes #1508
This commit is contained in:
parent
5de2f969e3
commit
ceeac9b982
|
@ -304,7 +304,12 @@ Collection.prototype.updateDocument = async function (
|
|||
};
|
||||
|
||||
this.documentStructure = updateChildren(this.documentStructure);
|
||||
await this.save({ transaction });
|
||||
|
||||
// Sequelize doesn't seem to set the value with splice on JSONB field
|
||||
// https://github.com/sequelize/sequelize/blob/e1446837196c07b8ff0c23359b958d68af40fd6d/src/model.js#L3937
|
||||
this.changed("documentStructure", true);
|
||||
|
||||
await this.save({ fields: ["documentStructure"], transaction });
|
||||
await transaction.commit();
|
||||
} catch (err) {
|
||||
if (transaction) {
|
||||
|
@ -357,10 +362,11 @@ Collection.prototype.removeDocumentInStructure = async function (
|
|||
document.id
|
||||
);
|
||||
|
||||
await this.save({
|
||||
...options,
|
||||
transaction,
|
||||
});
|
||||
// Sequelize doesn't seem to set the value with splice on JSONB field
|
||||
// https://github.com/sequelize/sequelize/blob/e1446837196c07b8ff0c23359b958d68af40fd6d/src/model.js#L3937
|
||||
this.changed("documentStructure", true);
|
||||
|
||||
await this.save({ ...options, fields: ["documentStructure"], transaction });
|
||||
await transaction.commit();
|
||||
} catch (err) {
|
||||
if (transaction) {
|
||||
|
|
|
@ -144,7 +144,9 @@ describe("#updateDocument", () => {
|
|||
|
||||
await collection.updateDocument(newDocument);
|
||||
|
||||
expect(collection.documentStructure[0].children[0].title).toBe(
|
||||
const reloaded = await Collection.findByPk(collection.id);
|
||||
|
||||
expect(reloaded.documentStructure[0].children[0].title).toBe(
|
||||
"Updated title"
|
||||
);
|
||||
});
|
||||
|
@ -224,8 +226,10 @@ describe("#removeDocument", () => {
|
|||
// Remove the document
|
||||
await collection.deleteDocument(newDocument);
|
||||
|
||||
expect(collection.documentStructure.length).toBe(1);
|
||||
expect(collection.documentStructure[0].children.length).toBe(0);
|
||||
const reloaded = await Collection.findByPk(collection.id);
|
||||
|
||||
expect(reloaded.documentStructure.length).toBe(1);
|
||||
expect(reloaded.documentStructure[0].children.length).toBe(0);
|
||||
|
||||
const collectionDocuments = await Document.findAndCountAll({
|
||||
where: {
|
||||
|
|
Reference in New Issue