Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Deleting records from referenced tables.

Post Reply
rnott
Posts: 31
Joined: Fri Mar 14, 2014 6:14 pm

Deleting records from referenced tables.

Unread post by rnott »

I'm new to relational databases & nuBuilder...

How do you handle the problem that occurs when a user deletes records from referenced tables?

Using the nuBuilder invoice example... If a user was to delete a product, then all of the existing customer_product records that references that product_id would not know what the product code,name, etc. from that related product record.

Even if the user was to re-create the same product it would have a different product_id and therefore not show up on any existing invoices.

The only way I can think of to fix this problem is to get the database administrator to create a product with the same product_id value that was used on the existing customer_product records.
To prevent this problem, would you not allow anyone the ability to delete records from referenced tables?
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Deleting records from referenced tables.

Unread post by massiws »

rnott , you can manage these occurrences with PHP code in Before Save or After Delete tabs (see here)
nuGent
Posts: 11
Joined: Sat Jan 18, 2014 1:26 pm

Re: Deleting records from referenced tables.

Unread post by nuGent »

rnott, you are correct in your assumption that referenced items (eg items in lookup tables) must not be deleted (or created) by users otherwise havoc will ensue. Have a look into the concepts of 'referential integrity' and then apply appropriate permissions to save them from themselves. In a similar vein, once a unique product record has been created with a primary key, one should not change its key description.

Users often do silly things when adding new items in a parts list or a list of country codes etc:
1001: 15mm copper elbow
1002: 15mm coupling
...
1014: 15 mm coupling

It all makes work for the working man to do!

Cheers
John
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Deleting records from referenced tables.

Unread post by admin »

Australia has some weird postcodes eg.

Station Arcade 5000
Adelaide 5000
Adelaide 5001

In cases like this you need to rely on another field as the Primary Key.

In nuBuilder the PK is never seen by the user, relying on this, you should be fine.

Steven
Post Reply