Created
April 10, 2020 13:44
-
-
Save anirudhjain75/33f3fb6b30e409c1d455a51fcbf619b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function deleteRelationships(orm, transacting, mainEntity) { | |
const mainBBID = mainEntity.bbid; | |
const {relationshipSet} = mainEntity; | |
const otherBBID = []; | |
const otherEntities = []; | |
if (relationshipSet) { | |
relationshipSet.relationships.map((relationship) => { | |
if (relationship.sourceBbid === mainBBID) { | |
otherBBID.push(relationship.targetBbid); | |
} | |
else if (relationship.targetBbid === mainBBID) { | |
otherBBID.push(relationshipSet.sourceBbid); | |
} | |
}); | |
} | |
if (otherBBID.length) { | |
otherBBID.map(async (entityBbid) => { | |
console.log('This is called with ', entityBbid); | |
const otherEntity = await getEntityByBBID(orm, transacting, entityBbid); | |
const otherEntityRelationshipSet = await otherEntity.relationshipSet() | |
.fetch({require: false, transacting, withRelated: 'relationships'}); | |
console.log('otherEntity', await otherEntity); | |
console.log('RelationshipSet', await otherEntityRelationshipSet); | |
// console.log(await orm.func.relationship.getMasterRelationshipSetForEntity(orm, transacting, entityBbid)); | |
// const tempEntity = await getEntityByBBID(orm, transacting, entityBbid); | |
// console.log(tempEntity); | |
// const otherEntityRelationshipSet = await tempEntity.relationshipSet() | |
// .fetch({require: false, transacting, withRelated: 'relationships'}); | |
// console.log('temp entity', await otherEntityRelationshipSet); | |
// otherEntities.push(await otherEntityRelationshipSet); | |
}); | |
} | |
console.log(mainBBID); | |
console.log(otherBBID); | |
console.log(await otherEntities); | |
console.log(relationshipSet); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment