diff --git a/src/Umbraco.Core/Constants-Conventions.cs b/src/Umbraco.Core/Constants-Conventions.cs index 03240db872d0..09942ff49534 100644 --- a/src/Umbraco.Core/Constants-Conventions.cs +++ b/src/Umbraco.Core/Constants-Conventions.cs @@ -276,15 +276,16 @@ public static class RelationTypes public const string RelateParentMediaFolderOnDeleteAlias = "relateParentMediaFolderOnDelete"; /// - /// Returns the types of relations that are automatically tracked + /// Returns the types of relations that are automatically tracked. /// /// /// Developers should not manually use these relation types since they will all be cleared whenever an entity /// (content, media or member) is saved since they are auto-populated based on property values. /// + [Obsolete("This is no longer used, and will be removed in v12")] public static string[] AutomaticRelationTypes { get; } = { RelatedMediaAlias, RelatedDocumentAlias }; - // TODO: return a list of built in types so we can use that to prevent deletion in the uI + // TODO: return a list of built in types so we can use that to prevent deletion in the UI } public static class Udi diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs index 0162ba8d5239..ded99bf8bfd1 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -1042,8 +1042,13 @@ protected void PersistRelations(TEntity entity) var trackedRelations = new List(); trackedRelations.AddRange(_dataValueReferenceFactories.GetAllReferences(entity.Properties, PropertyEditors)); + var relationTypeAliases = trackedRelations + .Select(x => x.RelationTypeAlias) + .Distinct() + .ToArray(); + // First delete all auto-relations for this entity - RelationRepository.DeleteByParent(entity.Id, Constants.Conventions.RelationTypes.AutomaticRelationTypes); + RelationRepository.DeleteByParent(entity.Id, relationTypeAliases); if (trackedRelations.Count == 0) { @@ -1055,7 +1060,10 @@ protected void PersistRelations(TEntity entity) .ToDictionary(x => (Udi)x!, x => x!.Guid); // lookup in the DB all INT ids for the GUIDs and chuck into a dictionary - var keyToIds = Database.Fetch(Sql().Select(x => x.NodeId, x => x.UniqueId).From().WhereIn(x => x.UniqueId, udiToGuids.Values)) + var keyToIds = Database.Fetch(Sql() + .Select(x => x.NodeId, x => x.UniqueId) + .From() + .WhereIn(x => x.UniqueId, udiToGuids.Values)) .ToDictionary(x => x.UniqueId, x => x.NodeId); var allRelationTypes = RelationTypeRepository.GetMany(Array.Empty())?