Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Dec 08, 2014 @ 15:21
    Rasmus Fjord
    0

    Relation not being deleted

    Hey there 

    Ive created a small method which either saves or deletes a relation but when ever the .delete method is hit its not removed from the database. It worked fine for saving it but will not remove it.

    The method looks like this :

      var relationService = ApplicationContext.Current.Services.RelationService;
                IPublishedContent currentmember = Members.GetCurrentMember();
    
                var areRelated = relationService.AreRelated(currentmember.Id, ProjectId, "memberFollow");
    
                var relType = relationService.GetRelationTypeByAlias("memberFollow");
                IRelation r = new Relation(currentmember.Id, ProjectId, relType);
                if (!areRelated)
                {
    
                    relationService.Save(r);
                }
                else
                {
    
                    relationService.Delete(r);
    
                }

     

    And the delete is hit but nothing happens. My relation looks like this :

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Dec 09, 2014 @ 11:08
    Morten Christensen
    100

    I believe the problem is that you are deleting a "new" relation and not an existing relation.

    With IRelation r = new Relation(currentmember.Id, ProjectId, relType); you are creating a new Relation that does not have an identity (id) yet. It won't have an identity until its saved or loaded from the service/database. You will have to call relationService.Delete(r); with a relation that actually has an identity.

    Hope this helps,

    Morten Christensen

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Dec 09, 2014 @ 11:11
    Rasmus Fjord
    0

    ARH of course makes sense !

    Ill get back to you if it works thx so far ! 

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Dec 09, 2014 @ 14:05
    Rasmus Fjord
    0

    It works like a charm Morten thx..

    A quick one if you know it (and ofcourse you do since your da champo).

      IRelation r = relationService.GetByRelationTypeAlias("memberFollow").First(x=> x.ParentId == currentmember.Id && x.ChildId == ProjectId);
    
                    relationService.Delete(r);

    Isnt there like a method for it ? Cannot seem to find it, right now im doing like above but dunno if its like a performence blocker(dont know much about the underlying part of C# and Lambda).

Please Sign in or register to post replies

Write your reply to:

Draft