Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Umbraco.Core/Constants-Conventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,16 @@ public static class RelationTypes
public const string RelateParentMediaFolderOnDeleteAlias = "relateParentMediaFolderOnDelete";

/// <summary>
/// Returns the types of relations that are automatically tracked
/// Returns the types of relations that are automatically tracked.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
[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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,13 @@ protected void PersistRelations(TEntity entity)
var trackedRelations = new List<UmbracoEntityReference>();
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)
{
Expand All @@ -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<NodeIdKey>(Sql().Select<NodeDto>(x => x.NodeId, x => x.UniqueId).From<NodeDto>().WhereIn<NodeDto>(x => x.UniqueId, udiToGuids.Values))
var keyToIds = Database.Fetch<NodeIdKey>(Sql()
.Select<NodeDto>(x => x.NodeId, x => x.UniqueId)
.From<NodeDto>()
.WhereIn<NodeDto>(x => x.UniqueId, udiToGuids.Values))
.ToDictionary(x => x.UniqueId, x => x.NodeId);

var allRelationTypes = RelationTypeRepository.GetMany(Array.Empty<int>())?
Expand Down