mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixed recursion issue
This commit is contained in:
parent
bbc3347717
commit
0bc57c68f9
@ -808,6 +808,10 @@ export class EntityMetadata {
|
||||
compareEntities(firstEntity: any, secondEntity: any) {
|
||||
const firstEntityIds = this.getEntityIdMap(firstEntity);
|
||||
const secondEntityIds = this.getEntityIdMap(secondEntity);
|
||||
// console.log("firstEntity: ", firstEntity);
|
||||
// console.log("firstEntityIds: ", firstEntityIds);
|
||||
// console.log("secondEntity: ", secondEntity);
|
||||
// console.log("secondEntityIds: ", secondEntityIds);
|
||||
return this.compareIds(firstEntityIds, secondEntityIds);
|
||||
}
|
||||
|
||||
|
||||
@ -160,9 +160,7 @@ export class SubjectBuilder<Entity extends ObjectLiteral> {
|
||||
.forEach(([relation, value, valueMetadata]) => {
|
||||
|
||||
// if we already has this entity in list of operated subjects then skip it to avoid recursion
|
||||
// here we should use findByEntityLike instead of findByEntity because findByEntityLike relays on ids,
|
||||
// however these ids are missing in insert operation and using findByEntityLike can bring recursion
|
||||
const alreadyExistValueSubject = this.findByEntity(value);
|
||||
const alreadyExistValueSubject = this.findByEntityLike(valueMetadata.target, value);
|
||||
if (alreadyExistValueSubject) {
|
||||
if (alreadyExistValueSubject.canBeInserted === false)
|
||||
alreadyExistValueSubject.canBeInserted = relation.isCascadeInsert === true;
|
||||
@ -197,7 +195,7 @@ export class SubjectBuilder<Entity extends ObjectLiteral> {
|
||||
.forEach(([relation, value, valueMetadata]) => {
|
||||
|
||||
// if we already has this entity in list of operated subjects then skip it to avoid recursion
|
||||
const alreadyExistValueSubject = this.findByEntity(value);
|
||||
const alreadyExistValueSubject = this.findByEntityLike(valueMetadata.target, value);
|
||||
if (alreadyExistValueSubject) {
|
||||
alreadyExistValueSubject.mustBeRemoved = true;
|
||||
return;
|
||||
@ -744,19 +742,6 @@ export class SubjectBuilder<Entity extends ObjectLiteral> {
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds subject where entity is exactly given subject's entity.
|
||||
* Comparision made by reference.
|
||||
*/
|
||||
protected findByEntity(entity: ObjectLiteral): Subject|undefined {
|
||||
return this.operateSubjects.find(subject => {
|
||||
if (!subject.hasEntity)
|
||||
return false;
|
||||
|
||||
return subject.entity === entity;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds subject where entity like given subject's entity.
|
||||
* Comparision made by entity id.
|
||||
@ -766,6 +751,9 @@ export class SubjectBuilder<Entity extends ObjectLiteral> {
|
||||
if (!subject.hasEntity)
|
||||
return false;
|
||||
|
||||
if (subject.entity === entity)
|
||||
return true;
|
||||
|
||||
return subject.entityTarget === entityTarget && subject.metadata.compareEntities(subject.entity, entity);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user