Skip to content

Commit

Permalink
fix for RelationTypeMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendy committed May 18, 2014
1 parent d651283 commit 2420f94
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void SaveEvent(IEnumerable<IContentBase> savedEntities)
LegacyRelationType relationType = LegacyRelationType.GetByAlias(this.GetRelationTypeAlias(propertyType));
if (relationType != null)
{
DeleteRelations(relationType, savedEntity.Id, true, string.Empty);
DeleteRelations(relationType, savedEntity.Id, true, GetInstanceIdentifier(propertyType));

if (property.Value != null)
{
Expand All @@ -44,7 +44,7 @@ private void SaveEvent(IEnumerable<IContentBase> savedEntities)
int pickedId;
if (int.TryParse(key, out pickedId))
{
CreateRelation(relationType, savedEntity.Id, pickedId, true, GetInstanceIdentifier(property));
CreateRelation(relationType, savedEntity.Id, pickedId, true, GetInstanceIdentifier(propertyType));
}
}
}
Expand All @@ -70,7 +70,7 @@ private void DeleteEvent(IEnumerable<IContentBase> deletedEntities)
if (relationType != null)
{
// clean out any relations refering to a deleted item
DeleteRelations(relationType, deletedEntity.Id, true, GetInstanceIdentifier(property));
DeleteRelations(relationType, deletedEntity.Id, true, GetInstanceIdentifier(propertyType));
}
}
}
Expand Down Expand Up @@ -128,9 +128,9 @@ private string GetRelationTypeAlias(PropertyType propertyType)
.Value;
}

private static string GetInstanceIdentifier(Property property)
private static string GetInstanceIdentifier(PropertyType propertyType)
{
return property.Key.ToString();
return propertyType.DataTypeDefinitionId.ToString();
}

/// <summary>
Expand All @@ -143,6 +143,7 @@ private static void DeleteRelations(LegacyRelationType relationType, int context

if (reverseIndexing || relationType.Dual)
{
getRelationsSql += "(";
getRelationsSql += "childId = " + contextId.ToString();
}
if (relationType.Dual) // need to return relations where content node id is used on both sides
Expand All @@ -154,6 +155,7 @@ private static void DeleteRelations(LegacyRelationType relationType, int context
getRelationsSql += "parentId = " + contextId.ToString();
}

getRelationsSql += ")";
getRelationsSql += " AND comment = '" + instanceIdentifier + "'";

using (var relations = uQuery.SqlHelper.ExecuteReader(getRelationsSql))
Expand Down

0 comments on commit 2420f94

Please sign in to comment.