Backendless Support
 
Answered

Deleting one to one relationship .Net

I have a Table called Group with a column "DefaultSubGroup" which is a one to one relationship to a table called SubGroup. I fail to set the relationship and clear it in the same session. Here are the steps that cause the problem.

1- DefaultSubGroup for MyGroup is initially null

2- Set DefaultSubGroup for MyGroup to a SubGroup "defaultSubGroup".

3- Save MyGroup

4- Clear DefaultSubGroup for MyGroup by setting it to null

5- Save MyGroup

After these steps somehow DefaultSubGroup for MyGroup remains set to defaultSubGroup object and is not cleared. If i refetch MyGroup Object then clear DefaultSubGroup it works.

Code for setting DefaultSubGroup

  1. MyGroup.DefaultSubGroup = defaultSubGroup;
  2. AsyncCallback<Group> saveCallBack = new AsyncCallback<Group>(
  3. group =>
  4. {
  5. //
  6. },
  7. fault =>
  8. {
  9. //
  10. });
  11. Backendless.Data.Of<Group>().Save(MyGroup, saveCallBack);

Code for clearing the relationship

  1. MyGroup.DefaultSubGroup = null;
  2. AsyncCallback<Group> saveCallBack = new AsyncCallback<Group>(
  3. group =>
  4. {
  5. //
  6. },
  7. fault =>
  8. {
  9. //
  10. });
  11. Backendless.Data.Of<Group>().Save(MyGroup, saveCallBack);

Am I doing something wrong?

Leave a Comment

Comments (1)

photo
1

Hi Maheed,In order to remove relation (set it to null), you need to first load it. So add a find call to your workflow and it should work fine.