String associationRole = tupleContext.getRole( operation.getColumn() );
if ( !processedAssociationRoles.contains( associationRole ) ) {
processedAssociationRoles.add( associationRole );
EntityKey targetKey = getEntityKey( tuple, tupleContext.getAssociatedEntityKeyMetadata( operation.getColumn() ) );
// delete the previous relationship if there is one; for a to-one association, the relationship won't have any
// properties, so the type is uniquely identifying it
Iterator<Relationship> relationships = node.getRelationships( withName( associationRole ) ).iterator();
if ( relationships.hasNext() ) {
relationships.next().delete();
}
// create a new relationship
Node targetNode = entityQueries.get( targetKey.getMetadata() ).findEntity( executionEngine, targetKey.getColumnValues() );
node.createRelationshipTo( targetNode, withName( associationRole ) );
}
}
}