Replies: 7 comments 5 replies
-
I believe you should change the type of the existing change set and recompute that: cs.type = ChangeSetType.UPDATE;
args.uow.recomputeSingleChangeSet(cs.entity); |
Beta Was this translation helpful? Give feedback.
-
The loaded entity has deleted to false. onFlush(args: FlushEventArgs) {
const changeSets: ChangeSet<Partial<Person>>[] = args.uow.getChangeSets().filter(cs =>
cs.entity instanceof Person &&
cs.type === ChangeSetType.DELETE
);
for (const cs of changeSets) {
if (!cs.entity.deleted) {
// cs.entity.deleted = true;
cs.payload.deleted = true;
cs.type = ChangeSetType.UPDATE;
// args.uow.recomputeSingleChangeSet(cs.entity);
// args.uow.computeChangeSet(cs.entity, ChangeSetType.UPDATE);
}
}
} |
Beta Was this translation helpful? Give feedback.
-
onFlush(args: FlushEventArgs) {
const changeSets: ChangeSet<Partial<Person>>[] = args.uow.getChangeSets().filter(cs =>
cs.entity instanceof Person &&
cs.type === ChangeSetType.DELETE
);
for (const cs of changeSets) {
if (!cs.entity.deleted) {
cs.entity.deleted = true;
// cs.payload.deleted = true;
cs.type = ChangeSetType.UPDATE;
args.uow.recomputeSingleChangeSet(cs.entity);
// args.uow.computeChangeSet(cs.entity, ChangeSetType.UPDATE);
}
}
} recomputeSingleChangeSet(entity) {
console.log('entity', entity);
const changeSet = this.changeSets.get(entity);
if (!changeSet) {
return;
}
console.log('changeSet', changeSet);
const cs = this.changeSetComputer.computeChangeSet(entity);
console.log('cs', cs);
/* istanbul ignore else */
console.log('checkUniqueProps', !this.checkUniqueProps(changeSet));
if (cs && !this.checkUniqueProps(changeSet)) {
console.log('if');
console.log('Assign', changeSet.payload, cs.payload);
Object.assign(changeSet.payload, cs.payload);
(0, entity_1.helper)(entity).__originalEntityData = this.comparator.prepareEntity(entity);
console.log('after prepare entity', (0, entity_1.helper()(entity).__originalEntityData));
(0, entity_1.helper)(entity).__touched = false;
}
} Let me know if you want me to add more logs: entity Person { id: '11', name: 'Adrian Smith', deleted: true }
changeSet ChangeSet<Person> {
entity: Person { id: '11', name: 'Adrian Smith', deleted: true },
type: 'update',
payload: {},
name: 'Person',
rootName: 'Person',
collection: 'person',
schema: undefined
}
cs ChangeSet<Person> {
entity: Person { id: '11', name: 'Adrian Smith', deleted: true },
type: 'update',
payload: { deleted: true },
name: 'Person',
rootName: 'Person',
collection: 'person',
schema: undefined,
originalEntity: { id: '11', name: 'Adrian Smith', deleted: false }
}
checkUniqueProps false Didn't enter into the |
Beta Was this translation helpful? Give feedback.
-
By commenting out some code it works recomputeSingleChangeSet(entity) {
console.log('entity', entity);
const changeSet = this.changeSets.get(entity);
if (!changeSet) {
return;
}
console.log('changeSet', changeSet);
const cs = this.changeSetComputer.computeChangeSet(entity);
console.log('cs', cs);
/* istanbul ignore else */
console.log('checkUniqueProps', !this.checkUniqueProps(changeSet));
if (cs /*&& !this.checkUniqueProps(changeSet)*/) {
console.log('if');
console.log('Assign', changeSet.payload, cs.payload);
Object.assign(changeSet.payload, cs.payload);
/*
(0, entity_1.helper)(entity).__originalEntityData = this.comparator.prepareEntity(entity);
console.log('after prepare entity', (0, entity_1.helper()(entity).__originalEntityData));
(0, entity_1.helper)(entity).__touched = false;
*/
}
} |
Beta Was this translation helpful? Give feedback.
-
I see, thanks. I think we either shouldn't have the |
Beta Was this translation helpful? Give feedback.
-
true, sorry. It's working now... thanks! |
Beta Was this translation helpful? Give feedback.
-
I'm trying to set an entity as deleted when it's being deleted for the first time. Looking at the docs I can see an example that changes an update for delete in the onFlush method.
The code below changes the type from delete to update but the payload is empty and so nothing is updated:
So the only workaround is removing the onFlush method and use beforeFlush:
Should the first approach do the job or is the second the only way to achieve it?
Beta Was this translation helpful? Give feedback.
All reactions