Topic: Parent-Child issue

Hi All,
The problem I'm having is related to my previous post about Join Issues. 
My Vessel/Owner problem in that post is working OK with no cascading tables, just lookup tables.
.
However now I need to add Equipment and the corresponding Service records for each piece of equipment.
.
Then when I Delete a piece of equipment I need the related Service records to go away.
.
I thought by using Cascade that it would take care of it, but not so.
I've attached a simple sample program to show you what I'm trying to do.
I'm not using any scripting, thinking it shouldn't be necessary because of the cascade feature?
I believe this function I'm trying to do should be about as basic and simple as it can be, but it's apparent that I'm not understanding something.
.
Thoughts will be appreciated.
Thanks Frank

Post's attachments

Attachment icon Equip Service.zip 325.72 kb, 175 downloads since 2021-08-09 

2 (edited by derek 2021-08-08 23:50:07)

Re: Parent-Child issue

Hi Frank,
Each item of equipment can have many services, so the relationship between the two tables needs to be set on the 'many' side which, in this case, is tblservice.  You have it set on tblequip. 
Change that and 'cascade delete' will work correctly.
Attached is a quick rework of your example (in two different styles) just so you can see it working (seeing is believing - LOL!). 
Try deleting an equipment record and the equipment record and all associated service records will be deleted.
Try deleting a 'service type' record and the 'service type' record will not be deleted if there are any service records using that 'service type' because 'cascade / delete' has not been set.

Post's attachments

Attachment icon equipservice options.zip 678.14 kb, 152 downloads since 2021-08-09 

Re: Parent-Child issue

Derek,
Thanks for looking over my example program.
I changed the relationship from Equip to Service, but it doesn't work, at least the way I have it set up.
.
It looks like the trouble is with the combobox I have on frmEquip.  I was trying to show the service options on the combobox so I could pick what I want for a new piece of equipment that I am adding.  Maybe I can't do it this way?
.
Based on my original example program, can you tell me what I'm doing wrong?
-
I'm going to look over the examples you included to see how I can adapt them to what I'm trying to do.
.
Thanks, Frank

4 (edited by derek 2021-08-09 11:06:51)

Re: Parent-Child issue

Hi Frank,
Based on your original attachment (equip service.zip), I am assuming that you will have one piece of equipment and it will need servicing many times..
IF this assumption is correct, then there is a one-to-many relationship between tblequip and tblservice and the following needs to be corrected:
1.  in the 'database tables', the relationship is removed from the 'one' table (tblequip) and added to the 'many' table (tblservice).
2.  the relationship needs to be flagged for 'cascade delete'
3.  on form frmequip, you should not have combobox cboservice - this would only ever allow you to have one service record rather than many service records.
4.  on frmservice, you need a combox to select the piece of equipment that the service is to be carried out on. 
Just because you have specified a relationship in the 'database tables' schema doesn't mean that it simply happens - the program doesn't know which specific piece of equipment in tblequip and which service record in tblservice you want to link - the program needs to be told.
Now, when you do things the 'standard' MVD way, you would start with a tablegrid that lists your equipment.  That would then call a form where you can maintain the equipment details and also shows a tablegrid listing the service records for that piece of equipment.  That in turn would call a form where you can maintain the service details. And when you follow this 'standard' way, then all of the keys that link a specific record in tblequip and specific records in tblservice are automatically being picked up by MVD and maintained for you.
However, in your project, you are not following this 'standard' approach (which is absolutely fine) but you need to understand that you therefore have to do more of the work yourself (hence the need for the combobox on 'frmservice' to select a piece of equipment - you are manually telling your program which specific record in tblequip links to the record in tblservice you are working on ).
If you follow all of the above, then 'cascade / delete' works as it's designed to.
In the attachment is your original project, your original project fixed and also an option for how you could approach it but it's just a suggestion (and probably not the way I would actually do it, but then I don't know the business logic nor the volumetrics behind your project). 
But no matter how you present the information to your users, if the underlying data structure is incorrect,  it's never going to work.
Regards,
Derek.

Post's attachments

Attachment icon fc.zip 1014.4 kb, 179 downloads since 2021-08-09 

Re: Parent-Child issue

Derek,
Thank you for the great explanation.  Actually I was pretty close to having everything as you describe.
I was just getting messed up on setting the relationships.  I already had the Equipment/Service forms set up and as soon as I fixed the relationships everything fell into place.
.
I've attached a PDF file with shots of my Equipment  and Service forms.
.
Next I'm going to work on Service dates.  I will need to predict a Next Service Date from the combination of Service Interval and Last Service date.  I've got some ideas but like any good plan I'm sure I'll run into challenges.  So you can rest assured I'll be back LOL.
.
Thanks so much to yourself and Brian for helping me to get as far as I have.
Frank

Post's attachments

Attachment icon Equipment Example.pdf 92.6 kb, 174 downloads since 2021-08-09