Drag/drop in a hierarchical tree deletes the child instance

If you think that something doesn't work in Aware IM post your message here
Post Reply
JonP
Posts: 287
Joined: Thu Feb 16, 2017 9:49 pm
Location: United States

Drag/drop in a hierarchical tree deletes the child instance

Post by JonP »

I have forms with lightweight hierarchical trees. To model the entire hierarchy in the lightweight fashion, I create the form in a BO that has a parent-child relationship to the BO I'm treeing and include both objects in the tree contents, selecting just the child attribute for each. I then set "Allow dropping nodes" to yes for those 2 attributes.

Everything seems to work fine. When I drag and drop a node onto another node, it indents the dropped node under the parent node as a child node as you would expect.

But if I click on it to edit, I get a message that says the record cannot be accessed and may have been deleted. If I close the form and come back, the record is gone (it was in fact deleted).

Screenshots are attached that shows the settings for the BO I'm treeing (the parent BO, "Account", has the same settings) and shows the error I encounter when I drag/drop, then select the dropped node.
Drag and drop issue.png
Drag and drop issue.png (55.49 KiB) Viewed 10756 times
Drag and drop issue 2nd.png
Drag and drop issue 2nd.png (52.84 KiB) Viewed 10756 times
v8.1 on Windows 10 / MySQL 5.6 (local), v8.1 on Windows Server 2016 / MySQL 5.6 (server)
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Re: Drag/drop in a hierarchical tree deletes the child insta

Post by tford »

I have not used trees recently, but I wonder if you need an Auto Refresh added.
Tom - V8.8 build 3137 - MySql / PostGres
JonP
Posts: 287
Joined: Thu Feb 16, 2017 9:49 pm
Location: United States

Re: Drag/drop in a hierarchical tree deletes the child insta

Post by JonP »

No dice on auto refresh, but I think I figured out what's happening.

I'm using 2 BOs with the parent BO only included to show the 1st level in the hierarchy. It has an owner/owned relationship with the other BO (om_Entities/Account). The lower levels use a hierarchical peer relationship between the same BO (pm_HasEntities/PartOf).

But the tree doesn't understand this and when I drag from the 1st level to a lower level, it tries to set Entity.PartOf to Entity.Account (or maybe the other way around), which naturally confuses the database and causes the record to be deleted.

I tested by setting the relationships using the form and when I drag from one lower level node to another, it works as expected.
v8.1 on Windows 10 / MySQL 5.6 (local), v8.1 on Windows Server 2016 / MySQL 5.6 (server)
aware_support
Posts: 7525
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: Drag/drop in a hierarchical tree deletes the child insta

Post by aware_support »

This is because your Account object has Parent/Child relationship with the Entity object (through the reference attribute). Therefore when the record of the Entity is moved it is deleted from its owner and because the owner is the parent, the record of the child is automatically deleted. Change this relationship to PEER instead.
Aware IM Support Team
JonP
Posts: 287
Joined: Thu Feb 16, 2017 9:49 pm
Location: United States

Re: Drag/drop in a hierarchical tree deletes the child insta

Post by JonP »

That makes sense. I had hoped the relationship between the two BOs could be untouched by a drag/drop because the change really is strictly a hierarchical one within a BO and not between those BOs. But in order to see the top level of that hierarchy, I can't avoid bringing in the 2nd BO to look down onto it, which corrupts that relationship whenever nodes are moved off the top level.

After switching to peer, my fix for that is to add the following rule to keep from losing the relationship since there is a danger of lost instances otherwise:

Code: Select all

If Entity.Account WAS CHANGED AND Entity.Account<>LoggedInPerson.Account Then 
Entity.Account=LoggedInPerson.Account
That seems to do the trick.

Furthermore, by solely relying on the tree for managing the hierarchy, my problem with infinite loops appears to be resolved because the tree (when set to auto-save and auto-refresh) resists my attempts at creating an infinite loop. Nice feature!
v8.1 on Windows 10 / MySQL 5.6 (local), v8.1 on Windows Server 2016 / MySQL 5.6 (server)
Post Reply