Page 1 of 1

PostPosted: Wed Apr 19, 2006 10:48 pm
by jvkranenburg
Hi Steve,

I'm on the point that's already described in SF issue 1449632.

#1449632
Check usage before delete
I would like to have a feature that can check if there
are childs using a record, on deletion.

E.g. When i sell something to a customer and I create
an invoice I don't want to be able to delete the
customer. Because the invoice doesn't have a customer
anymore.

Is this possible?
#1449632

But isn't this possible with a beforeDelete trigger? I tried to get this worked with the trigger but without success.

Do you have a good sugestion of isn't the trigger the solution for this problem?

Thanks, Jerry

PostPosted: Thu Apr 20, 2006 8:30 am
by shannah
Hi Jerry,

Yes, the beforeDelete() trigger should be a solution to this problem.

My thought is that something like the following should work:
Code: Select all
function beforeDelete(&$record){
   if ( isset($record) ){
       if ( $record->numReleatedRecords('Invoices') > 0 ){
           return Dataface_Error::permissionDenied('Sorry you cannot delete this customer because he has invoices');
       }
   }
}

Let me know how it goes.

PostPosted: Thu Apr 20, 2006 10:55 am
by shannah
Oops.. typo
$record->numReleatedRecords('Invoices')
should be
$record->numRelatedRecords('Invoices')

PostPosted: Thu Apr 20, 2006 2:48 pm
by jvkranenburg
Hi Steve,

Thanks for your solution. I tried it and it works perfect. This is exactly what I needed!

Didn't know the numRelatedRecords function thats why I couldn't get it work. :) But I found the description in the Dataface API Reference right now.

Thanks, Jerry