- Fix TERM-SYNONYMS.
authorMaciej Pasternacki <maciej@pasternacki.net>
Thu, 18 Dec 2008 00:19:59 +0000 (18 01:19 +0100)
committerMaciej Pasternacki <maciej@pasternacki.net>
Thu, 18 Dec 2008 00:19:59 +0000 (18 01:19 +0100)
src/taxonomy.lisp

index 644d6b7..f6a98ac 100644 (file)
@@ -287,17 +287,23 @@ TERM is always included in the returned list, and it is a first item.
 TERM may be also a list, whose first element is taxonomy object or
 name, and second element is term name.  This is a case of premature
 optimization."
-  (query-dao 'term
-             (sql (:select '* :from 'term
-                           :where (:and (:= 'term-taxonomy
-                                            (taxonomy-slug
-                                             (etypecase term
-                                               (term (term-taxonomy term))
-                                               (list (first term)))))
-                                        (:= (:lower 'term-text)
-                                            (:lower (etypecase term
-                                                      (term (term-text term))
-                                                      (list (string (second term)))))))))))
+  (etypecase term
+    (term (cons term
+                (mapcar #'cache-dao 
+                        (query-dao 'term
+                                   (sql (:select '* :from 'term
+                                                 :where (:and (:!= 'term-id (id term))
+                                                              (:= 'term-taxonomy
+                                                                  (taxonomy-slug (term-taxonomy term)))
+                                                              (:= (:lower 'term-text)
+                                                                  (:lower (term-text term))))))))))
+    (list (mapcar #'cache-dao
+                  (query-dao 'term
+                             (sql (:select '* :from 'term
+                                           :where (:and (:= 'term-taxonomy
+                                                            (taxonomy-slug (first term)))
+                                                        (:= (:lower 'term-text)
+                                                            (:lower (string (second term))))))))))))
 
 (defun apply-term (item term &key value order)
   "Apply TERM to ITEM, optionally setting its value to VALUE."