Issue 1449632 with beforeDelete Trigger

A place for users and developers of the Xataface to discuss and receive support.

Postby jvkranenburg » Wed Apr 19, 2006 10:48 pm

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
jvkranenburg
 
Posts: 11
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Apr 20, 2006 8:30 am

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.
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Apr 20, 2006 10:55 am

Oops.. typo
$record->numReleatedRecords('Invoices')
should be
$record->numRelatedRecords('Invoices')
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby jvkranenburg » Thu Apr 20, 2006 2:48 pm

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
jvkranenburg
 
Posts: 11
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 6 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved