   (fn [select*-1 entity-2-rows]
     (reduce
      (fn [query entity-2-row]
-       (where query
-              (let [p (exists
-                       (subselect rel-entity
-                                  (fields field-fk-id-1)
-                                  (where (and
-                                          (= field-fk-id-2 (field-id-2 entity-2-row))
-                                          (= field-fk-id-1 (-> select*-1
-                                                               :ent
-                                                               :table
-                                                               (str "." (name field-id-1))
-                                                               keyword)))
-                                         )))]
-                (if not? (not p) p))))
+       (kc/where query
+                 (let [p (exists
+                          (kc/subselect rel-entity
+                                        (kc/fields field-fk-id-1)
+                                        (kc/where (and
+                                                   (= field-fk-id-2 (field-id-2 entity-2-row))
+                                                   (= field-fk-id-1 (-> select*-1
+                                                                        :ent
+                                                                        :table
+                                                                        (str "." (name field-id-1))
+                                                                        keyword)))
+                                                  )))]
+                   (if not? (not p) p))))
      select*-1 entity-2-rows)))
 
 ;; END SQL TOOLS



(defn file-pred-images* [query* & [not?]]
  (where query*
         {:content_type [(if not? not-in in) ["image/gif"
                                              "image/jpeg"
                                              "image/pjpeg"
                                              "image/png"
                                              "image/svg+xml"
                                              "image/tiff"]]}))

(defn file-pred-galleria? [query*]
  (where query* (= :galleria true)))






(defn files_rel-delete [files-rel-field {file-id :id} {rel-id :id}]
  (kc/delete files_rel (kc/where (and (= :files_id file-id)
                                      (= files-rel-field rel-id)))))

(defn files_rel-select-files-by-* [row files-rel-field]
  ((com-defn-pred-rows-by-rel? :id :id files_rel :files_id files-rel-field)
