Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

where's the referential integrity?


This topic is 5818 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have a simple 2 table parent child relationship. I store the parent primary key value (a unique ID) in a foreign key field in the child table.

No matter what I do, FM continues to allow the deletion of parent records with dependent children. I don't think that should be possible in a relational database. How do you maintain referential integrity like that?

I'm a newbie, so I may be missing something.

thanks in advance!

Hal

Posted

Hi Hal, welcome to FM Forums!

No matter what I do, FM continues to allow the deletion of parent records with dependent children.

As always, it is the Developer's responsibility to fully control functionality of a design. Some tables would warrant also deleting children (deleting an invoice should delete the lineitems as well) and some parent deletions would NOT warrant deleting children (two parent records sharing the SAME address shouldn't delete the address). Each parent/child relationship needs to be evaluated independently and, according to the business rules outlined, the developer then enforces those rules. How? All deletions should be 1) restricted using privileges when appropriate, 2) scripted and 3) you might use 'delete children when deleting parent' in the relation graph when appropriate.

You can restrict all Users from deleting from the FM Menu via privileges and then create a script which, table by table, asks and responds according to the rules and whether you graph allows cascading deletes (and whether your script is set to run with full privileges).

LaRetta :wink2:

Posted

Thanks for the advice. All I want to do is prevent a parent that has children from being deleted. You mention that this would have to be scripted. Can you point me in the direction of an example script that would prevent a parent with children from being deleted?

Posted (edited)

If [ not IsEmpty ( childTable::fk_parentID ) ]

Show Custom Dialog [ OK ; "This parent has kids. You can't delete it!" ]

Else

Delete Record/Request[]

End If

:wink2:

Edited by Guest
Added parenth
Posted

It doesn't have to be scripted. You can place this limitation in the access privileges for the table. A script in addition to the privileges is nice though because you can create a more polite interface.

Posted

Notice above, DJ, that I also said it could be controlled via privileges, that scripting was only one way. A small thing, but I didn't want you to think I didn't know about privilege restrictions on deletions. :wink2:

Posted

Thank you so much for the code LaRetta, that worked like a charm.

The privilege setting approach mentioned by D J would not work for me in this case because I would not want *any* user to be able to delete parents with children, even admin.

Posted

Don't you know that I know that you know? But Hal9000 seemed to not know. Ya know?

Usually if someone knows that someone who posted previously knew, then they would say, "As so-and-so already mentioned..." so I assumed you didn't know that I knew or that I had already said so, or you would have said you knew I knew. You know?

I said it was a small thing which you didn't seem to know either. :wink2:

Posted

The privilege setting approach mentioned by D J would not work for me in this case because I would not want *any* user to be able to delete parents with children, even admin.

That is not possible under any circumstances. Users with full-access privileges can do anything they want - same as you - and can override any restrictions you have placed.

As LaRetta wrote in her first post, you must FIRST take away user's privilege to delete records AND THEN provide them with a scripted alternative. If you have restricted users from deleting records altogether, then the script is the only way for them to override the restriction. If your restriction is conditional, then the script is merely a cosmetic measure (as DJ wrote). But in any case, a script by itself cannot provide any real security measures.

Posted

Usually if someone knows that someone who posted previously knew, then they would say, "As so-and-so already mentioned..." so I assumed you didn't know that I knew or that I had already said so, or you would have said you knew I knew. You know?

I said it was a small thing which you didn't seem to know either. :wink2:

I hope you guys know that you guys gave me a migraine. You know? :

This topic is 5818 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.