loulou
|
| Posted: 02/28/2002, 1:11 PM |
|
In menu tree (ASP + template), how to prevent the deletion of a category that is "parent" of others (in relation with) ? Like menu tree uses only one table, the database integrity seems impossible to obtain with relationships...Got an idea or a sample code ?
|
|
|
 |
Nicole
|
| Posted: 03/01/2002, 1:54 AM |
|
Hello,
in before delete event try to search on table in order to count record where par_category field is equals to value of primary key field of current record. If such records exist it means that this category is used as parent for any records. In this case forbid its deletion.
|
|
|
 |
loulou
|
| Posted: 03/01/2002, 6:04 PM |
|
Thank you for your answer.
But do you know the code to do it?
I think something like:
if par_category_id <> "" then
xxxxxx ?
end if
|
|
|
 |
Nicole
|
| Posted: 03/04/2002, 2:10 AM |
|
Hello,
sample code could be:
rec_number = dLookUp("categories_table", "count(category_id)", "parent_category_id=" ToSQL(pPKcategory_id, "Number"))
if rec_number > 0 then
sSQL = ""
end if
I propose you to create Custom Action event rather then BeforeDelete event and put code there.
|
|
|
 |
antman
|
| Posted: 03/29/2002, 3:50 AM |
|
In the previous posting:
rec_number = dLookUp("categories_table", "count(category_id)", "parent_category_id=" ToSQL(pPKcategory_id, "Number"))
Change to
rec_number = dLookUp("categories_table", "category_id", "parent_category_id=".ToSQL(pPKcategory_id, "Number")."LIMIT 1")
count(*) requires parsing the whole db and is therefore slower.
I havent tested placing "LIMIT=1" there thus fooling dLookUp function, but I think it should work.
|
|
|
 |
|