Possible Bug - Parent/Child Object Issues

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
kaygee1
Posts: 30
Joined: Tue Sep 22, 2015 11:43 pm

Possible Bug - Parent/Child Object Issues

Post by kaygee1 »

I want to limit the number of child objects that a parent can have. So I setup a rule in the Parent Object.
IF LIST_SIZE(Parent.Children) > 1 THEN REPORT ERROR

The parent object is a new unsaved object and then children objects are being added using Add New Reference.
Adding the child object is fine. The problem is when I add more than 1 object (I put it to one just for easy testing), LIST_SIZE doesn't update properly. It stays stuck at 1 in the log. So it never triggers the Error.

Ideally what I'd like to do is prevent the user from even trying to add a new reference if there's x number of children already in the list if anyone has a way of doing that. I figured worse case is I could trigger an error after x number of child objects.
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Re: Possible Bug - Parent/Child Object Issues

Post by tford »

Ideally what I'd like to do is prevent the user from even trying to add a new reference if there's x number of children already in the list if anyone has a way of doing that. I figured worse case is I could trigger an error after x number of child objects.
You could have an attribute in the parent BO that tracks the number of children. Sounds like you would want the rule that updates the number of children to be dynamic.

Then you can make the operation to add children be conditional ... not available is the number of children is > x.
Tom - V8.8 build 3137 - MySql / PostGres
kaygee1
Posts: 30
Joined: Tue Sep 22, 2015 11:43 pm

Re: Possible Bug - Parent/Child Object Issues

Post by kaygee1 »

You could have an attribute in the parent BO that tracks the number of children. Sounds like you would want the rule that updates the number of children to be dynamic.

Then you can make the operation to add children be conditional ... not available is the number of children is > x.
This exactly what I want to do. I tried this but couldn't get it to work. I used the rules:

IF ChildObject WAS ADDED TO ParentObject.Children THEN INCREASE ParentObject.ChildCounter BY 1
IF ChildObject WAS REMOVED FROM ParentObject.Children THEN DECREASE ParentObject.ChildCounter BY 1

But looking at the logs, the WAS ADDED TO/WAS REMOVED FROM clause was never triggered. I tried setting it to work with the UI dynamically and still nothing.
I'm wondering if it had something to do with the ParentObject not being saved.
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Re: Possible Bug - Parent/Child Object Issues

Post by BenHayat »

kaygee1 wrote:
You could have an attribute in the parent BO that tracks the number of children. Sounds like you would want the rule that updates the number of children to be dynamic.

Then you can make the operation to add children be conditional ... not available is the number of children is > x.
This exactly what I want to do. I tried this but couldn't get it to work. I used the rules:

IF ChildObject WAS ADDED TO ParentObject.Children THEN INCREASE ParentObject.ChildCounter BY 1
IF ChildObject WAS REMOVED FROM ParentObject.Children THEN DECREASE ParentObject.ChildCounter BY 1

But looking at the logs, the WAS ADDED TO/WAS REMOVED FROM clause was never triggered. I tried setting it to work with the UI dynamically and still nothing.
I'm wondering if it had something to do with the ParentObject not being saved.
One comment on the rule on the parent regarding # of children.
just check if ChilObject Was Changed and then use COUNT function of children and store it in parent. This way there is never a mismatch. I use it all the time and works.
kaygee1
Posts: 30
Joined: Tue Sep 22, 2015 11:43 pm

Re: Possible Bug - Parent/Child Object Issues

Post by kaygee1 »

if ChilObject Was Changed and then use COUNT function of children and store it in parent
I'm going to give this a go again. This was the first way I tried to do it but the WAS CHANGED event wasn't getting triggered kinda like how the WAS ADDED TO didn't seem to get triggered. But I'll try again.
kaygee1
Posts: 30
Joined: Tue Sep 22, 2015 11:43 pm

Re: Possible Bug - Parent/Child Object Issues

Post by kaygee1 »

Okay just so I don't think I'm seeing things. I've attached a screenshot.

You can see my child table, with three objects in it (scroll down in the attached image). However looking at the LogViewer you see that COUNT in a rule on the parent object Questionnaire, only returns a count of 1. I went to 3 just to see if there was a timing issue in hopes that it would say there were 2 child objects and that it was just doing the count before one of the child objects was being attached.

I'm using Add New Reference to add the child objects. But it's being added to a Parent Object that is initially unsaved. I'm wondering if that has something to do with what I'm seeing.

I'm using version 7.1 build 2223
Attachments
countingissue.png
countingissue.png (26.51 KiB) Viewed 23350 times
BLOMASKY
Posts: 1470
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: Possible Bug - Parent/Child Object Issues

Post by BLOMASKY »

how about if in the Parent BO you have an attribute called noChildren
In the rules for this BO

IF Parent.om_Children WAS CHANGED or Children FROM Parent.om_Children WAS CHANGED THEN
Parent.noChildren = COUNT Children.ID WHERE (Children in Parent.om_Children)

(I know you only need one of the "WAS CHANGED" clauses, but I never remember which one is triggered if records are added and which is triggered when existing records are changed)

Then, as someone smarter than me suggested, you only enable the button to add children when Parent.noChildren < maxnumber

bruce
kaygee1
Posts: 30
Joined: Tue Sep 22, 2015 11:43 pm

Re: Possible Bug - Parent/Child Object Issues

Post by kaygee1 »

Thanks Bruce,

I'll give it a go, but I don't think that's the problem. The COUNT is off and as long as that is the issue I'm not able to prevent the button from showing/not showing.

That being said, how would you enable/disable the add children feature? I'm digging in the documentation and looking at the available options but don't see how it's possible.

Cheers,

Kevin
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Re: Possible Bug - Parent/Child Object Issues

Post by tford »

Kevin,

Attached is a demo BSV that shows how this can work. Note that this BSV is V6 since that is what I had open today.

To use the demo:
1) Click "Set max children" - enter the max number of children in a parent here. This is stored in SystemSettings.

2) Click Edit on the admin user in the Users Query. You'll note that the Add New Child button will appear / disappear at the proper time according to the number in Max Children attribute. You can also delete children which will update the number of children for that user + the Add New Children button may reappear if the user now has less than the Max Children.
Attachments
ParentChildDemo.zip
(34.47 KiB) Downloaded 579 times
Tom - V8.8 build 3137 - MySql / PostGres
kaygee1
Posts: 30
Joined: Tue Sep 22, 2015 11:43 pm

Re: Possible Bug - Parent/Child Object Issues

Post by kaygee1 »

Tom this is excellent, it took me a bit to find how it was setup, but I've learned a lot in just 5 minutes and for that I thank you!

And furthermore, this actually proves that there's something amiss with how AwareIM handles New Objects.

It works perfectly with already stored objects (Edit User).

However, if you click on New Object and create a regular user, it opens the same form to add children, but the Add Children button is not visible!

RegularUser.Nbr_children<SystemSettings.MaxChildren OR RegularUser.Nbr_children IS UNDEFINED

Looking at the log, nbr_children is set to 0, but it still doesn't display the button. I suspect that RegularUser isn't properly defined for new objects and so the criteria above fails. Although I couldn't see the criteria even processed in the log. I'm going to check if it's processed when in edit mode.
pureist
Posts: 427
Joined: Sun Jan 24, 2016 10:00 pm

Re: Possible Bug - Parent/Child Object Issues

Post by pureist »

Whenever there might be children involved, I reckon it's always best to create a blank parent instance and edit it, when the user initiates creation of a new parent instance.
Doesn't take much to clean up any blank parents which don't convert to real instances by having their data completed.
kaygee1
Posts: 30
Joined: Tue Sep 22, 2015 11:43 pm

Re: Possible Bug - Parent/Child Object Issues

Post by kaygee1 »

Yeah that's a workaround. But then it potentially causes other problems. The ability to set required fields becomes complicated.
pureist
Posts: 427
Joined: Sun Jan 24, 2016 10:00 pm

Re: Possible Bug - Parent/Child Object Issues

Post by pureist »

Don't bother setting any required properties. Use NO VALIDATION or NO RULES so you can create a blank new record.
kaygee1
Posts: 30
Joined: Tue Sep 22, 2015 11:43 pm

Re: Possible Bug - Parent/Child Object Issues

Post by kaygee1 »

Ahhhh, that's interesting! Let me see how that goes.
Post Reply