                            (webdoc-pred-by-tags? (conj tags-rows tag-row))
                            com-exec-1)]))
        doall
-       transaction))
+       kdb/transaction))
 
 
 

(defn com-save-for-field
  "Сохранить сущность"
  [entity field row]
  (transaction
   (let [r (update entity (set-fields row) (where (= field (row field))))]
     (if (= r 0)
       (insert entity (values row))
       (first (select entity (where (= field (row field)))))))))

(defn com-save-for-field-2
  "Сохранить сущность"
  [entity field-1 field-2 row]
  (transaction
   (let [r (update entity (set-fields row) (where (and
                                                   (= field-1 (row field-1))
                                                   (= field-2 (row field-2))
                                                   )))]
     (if (= r 0)
       (insert entity (values row))
       (first (select entity (where (and
                                     (= field-1 (row field-1))
                                     (= field-2 (row field-2))))))))))

(defn com-save-for-id
  "Сохранить сущность"
  [entity row]
  (transaction
   (let [r (update entity (set-fields row) (where (= :id (row :id))))]
     (if (= r 0)
       (insert entity (values row))
       (first (select entity (where (= :id (row :id)))))))))

(defn com-delete*
  "Удалить сущность"
  [entity]
  (delete* entity))

(defn com-delete-for-id
  "Удалить сущность"
  [entity]
  (delete* entity))

(defn com-delete-for-id
  "Удалить сущность по id"
  [entity id]
  (delete entity (where (= :id id))))

(defn com-find
  "Найти сущность по :id"
  [entity id]
  (let [rows (select entity (where (= :id id)))]
    (cond (empty? rows) nil
          (< 1 (count rows)) (do
                               (println "Внимание! По com-find нашел более одной записи по id "

(defn webdoc-one-row-by-tags
  ([tags-rows webdoc-entity]
   (-> webdoc-entity
       kc/select*
       ((com-defn-pred-rows-by-rels? :id :id  webdoctag :webdoc_id :tag_id) tags-rows)
       (kc/order :id :desc)
       com-exec-1)))

#_(defn webdoc-pred-by-tag--nil-other*-se?
