Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anirudhjain75/33f3fb6b30e409c1d455a51fcbf619b5 to your computer and use it in GitHub Desktop.
Save anirudhjain75/33f3fb6b30e409c1d455a51fcbf619b5 to your computer and use it in GitHub Desktop.
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