From: Maciej Pasternacki Date: Mon, 8 Dec 2008 02:00:54 +0000 (+0100) Subject: - Purge empty terms. X-Git-Url: https://repo.or.cz/w/cl-trane.git/commitdiff_plain/c99aa32bdfef6cdbfab753f38382793529b01598 - Purge empty terms. --- diff --git a/src/taxonomy.lisp b/src/taxonomy.lisp index 31275b3..5776b2b 100644 --- a/src/taxonomy.lisp +++ b/src/taxonomy.lisp @@ -335,10 +335,16 @@ not present before." :none)) (defun unbind-term (item term) - "Deletes association between ITEM and TERM." - (query (:delete-from 'item-term :where - (:and (:= 'item-id (id item)) - (:= 'term-id (id term)))))) + "Deletes association between ITEM and TERM. + +If PURGE-EMPTY is non-NIL (default), deletes also from TERM table if +no more items refer to this term." + (execute (:delete-from 'item-term :where + (:and (:= 'item-id (id item)) + (:= 'term-id (id term))))) + (execute (:delete-from 'term :where (:and (:= 'term-id (id term)) + (:not (:exists (:select '* :from 'item-term + :where (:= 'term-id (id term))))))))) (defun item-terms (item &optional taxonomy) "List TERMs associated with ITEM in given TAXONOMY.