diff --git a/src/actors.js b/src/actors.js index b9783ee..cdbc7db 100644 --- a/src/actors.js +++ b/src/actors.js @@ -899,6 +899,10 @@ export async function mergeActors(targetActorId, sourceActorIds, comment, reqUse .update('alias_for', targetActorId) .whereIn('id', sourceActorIds) .returning(['id', 'alias_for']), + // aliases of the source actors become aliases of the target, so they aren't chained + trx('actors') + .update('alias_for', targetActorId) + .whereIn('alias_for', sourceActorIds), trx('actors_avatars') .update('actor_id', targetActorId) .whereIn('actor_id', sourceActorIds), @@ -912,8 +916,12 @@ export async function mergeActors(targetActorId, sourceActorIds, comment, reqUse const duplicateSourceProfiles = sourceProfiles.filter((profile) => newestSourceProfileMap[profile.entity_id] && newestSourceProfileMap[profile.entity_id] !== profile.id); // assign source actor profiles to target actor, unless a profile for that entity is already present + // the alias records the name the profile was found under, a profile that already had one keeps it mergedProfiles = await trx('actors_profiles') - .update('actor_id', targetActorId) + .update({ + actor_id: targetActorId, + alias_id: knex.raw('coalesce(alias_id, actor_id)'), + }) .whereIn('actor_id', sourceActorIds) .whereNotIn('entity_id', existingProfiles.map((profile) => profile.entity_id)) .whereNotIn('id', duplicateSourceProfiles.map((profile) => profile.id)) @@ -948,7 +956,7 @@ export async function mergeActors(targetActorId, sourceActorIds, comment, reqUse mergedSceneActors = await trx('releases_actors') .update({ actor_id: targetActorId, - alias_id: knex.raw('actor_id'), + alias_id: knex.raw('coalesce(alias_id, actor_id)'), // keep the credited name when the source actor was credited by its own alias }) .whereIn('actor_id', sourceActorIds) .returning('release_id');