Пример #1
0
        public override void RemapRelations(PXGraph graph, Relation relation, object oldRecord, object remapToRecord)
        {
            if (!CanProcess(relation))
            {
                return;
            }
            var oneToManyRelation = (OneToManyRelation)relation;

            Type childForeignKeyField = oneToManyRelation.Right.ReferenceField;
            Type deletingDacKeyField  = oneToManyRelation.Right.TargetField;

            PXCache deletingDacCache = graph.Caches[deletingDacKeyField.DeclaringType];

            object oldParentValue = deletingDacCache.GetValue(oldRecord, deletingDacKeyField.Name);
            object newValue       = deletingDacCache.GetValue(remapToRecord, deletingDacKeyField.Name);

            foreach (object correctingEntity in graph.SelectById(childForeignKeyField, oldParentValue))
            {
                ChangeReference(graph, oneToManyRelation.Right, correctingEntity, newValue);
            }
        }