        (text-field param-key-2 errors-2)))))
 
 (defmethod condition-control :date
-  [entity-key property-key]
-  (date-timestamp-condition-control entity-key property-key))
+  [& args]
+  (apply date-timestamp-condition-control args))
 
 (defmethod condition-control :timestamp
-  [entity-key property-key]
-  (date-timestamp-condition-control entity-key property-key))
+  [& args]
+  (apply date-timestamp-condition-control args))
 
 (defmethod condition-control :many-to-one
-  [entity-key property-key]
-  (let [param-key          (param-key entity-key property-key)
+  [entity-class-key property-key]
+  (let [param-key          (param-key entity-class-key property-key)
         param-key-key      (keyword (format "%s-key"    (name param-key)))
         param-key-name-key (keyword (format "%s-name--" (name param-key-key)))]
     [:div.form-group
      (label param-key-key (string/capitalize (dog-mission/translate param-key)))
      (hidden-field param-key-key (get-in *request* [:entity-params param-key-key]))
      [:div.input-group
-      (text-field {:class "form-control", :readonly "readonly"} param-key-name-key (format-property-param entity-key property-key (get-in *request* [:entity-params param-key-name-key])))
-      [:span.input-group-addon {:data-open-window-uri (to-uri (<< "/~(name (:table-key (property-schema entity-key property-key)))/select?target-element-id=~(URLEncoder/encode (name param-key-key))"))}
+      (text-field {:class "form-control", :readonly "readonly"} param-key-name-key (format-property-param entity-class-key property-key (get-in *request* [:entity-params param-key-name-key])))
+      [:span.input-group-addon {:data-open-window-uri (to-uri (<< "/~(name (:table-key (property-schema entity-class-key property-key)))/select?target-element-id=~(URLEncoder/encode (name param-key-key))"))}
        [:span.glyphicon.glyphicon-search]]]]))
 
 (defmethod condition-control :default
-  [entity-key property-key]
+  [entity-class-key property-key]
   nil)
 
 (defn pagination-control

      (apply $and conditions))))

(defmethod condition :integer
  [entity-key property-key]
  (range-condition entity-key property-key))

(defmethod condition :decimal
  [entity-key property-key]
  (range-condition entity-key property-key))

(defmethod condition :boolean
  [entity-key property-key]
  (let [param-value (get-in *request* [:entity-params (param-key entity-key property-key)])]
    (if-not (nil? param-value)
      (if param-value
        property-key
        ($not property-key)))))

(defmethod condition :date
  [entity-key property-key]
  (range-condition entity-key property-key))

(defmethod condition :timestamp
  [entity-key property-key]
  (range-condition entity-key property-key))

(defmethod condition :many-to-one
  [entity-key property-key]
  (if-let [param-value (get-in *request* [:entity-params (keyword (format "%s-key" (name (param-key entity-key property-key))))])]
    ($= (many-to-one-relationship-key-to-physical-column-key property-key) param-value)))

(defmethod condition :default
  [entity-key property-key]
  nil)

(defn condition-matched-entities-and-page
  [entity-key]
  (if (and (= (get-in *request* [:params :command]) "search") (empty? (:entity-param-errors *request*)))
    (let [pages      (->> (-> (->> (if-let [conditions (not-empty (keep (partial condition entity-key) (search-condition-property-keys entity-key)))]
                                     (apply $and conditions))
                                   (database-data @database-schema *transaction* entity-key)
                                   (database      @database-schema))
                              (get-condition-matched-rows entity-key))
                          ((apply partial sort-by (sort-keyfn-and-comp entity-key)))
                          (partition-all 20)
                          (not-empty))
          page-count (count pages)
          page       (let [request-page (Integer/parseInt (get-in *request* [:params :page]))]
                       (max (min request-page page-count) 1))]
      [(if (empty? pages)
         []
         (nth pages (dec page)))
       page-count
       page])))

(defn target-entity-database
  [entity-key uri-parameters]
  (->> (database-data @database-schema *transaction* entity-key ($= :key (UUID/fromString (:key uri-parameters))))
       (database      @database-schema)))

(defn index-controller
  [entity-key uri-parameters]
  (with-db-transaction'
    (apply index-view entity-key (condition-matched-entities-and-page entity-key))))

(defn select-controller
  [entity-key uri-parameters]
  (with-db-transaction'
    (apply select-view entity-key (condition-matched-entities-and-page entity-key))))

(defn new-controller
  [entity-key uri-parameters]
  (new-view entity-key {}))

(defn create-controller
  [entity-key uri-parameters]
  (with-db-transaction'
    (let [entity-schema (entity-schema entity-key)
          entity        (->> (reduce (fn [entity property-key]
                                       (let [many-to-one? (= (property-type entity-key property-key) :many-to-one)
                                             column-key   (cond-> property-key
                                                            many-to-one? (many-to-one-relationship-key-to-physical-column-key))
                                             param-key    (cond-> (param-key entity-key property-key)
                                                            many-to-one? (#(keyword (format "%s-key" (name %)))))
                                             errors       (not-empty (get-in *request* [:entity-param-errors param-key]))]
                                         (cond-> entity
                                           (not errors) (assoc column-key (get-in *request* [:entity-params param-key])))))
                                     {}
                                     (inputtable-property-keys entity-key)))]
      (if (not-empty (get-in *request* [:entity-param-errors]))
        (new-view entity-key entity)
        (let [database (-> (database @database-schema)
                           (assoc-in [entity-key (new-key)] entity))]
          (save! @database-schema database *transaction*)
          (layout (string/capitalize (dog-mission/translate :update-view-title (dog-mission/translate entity-key)))
                  (javascript-tag (<< "$.crossplane.goToWithMethodAndParams('~(to-uri (<< \"/~(name entity-key)\"))', 'get', ~(json/write-str (base64-decode (get-in *request* [:params :index-params]))));"))))))))
      
(defn edit-controller
  [entity-key uri-parameters]
  (with-db-transaction'
    (edit-view entity-key (get-in (target-entity-database entity-key uri-parameters) [entity-key (UUID/fromString (:key uri-parameters))]))))

(defn update-controller
  [entity-key uri-parameters]
  (with-db-transaction'
    (let [entity-schema (entity-schema entity-key)
          database      (->> (reduce (fn [database property-key]
                                       (let [many-to-one? (= (property-type entity-key property-key) :many-to-one)
                                             column-key   (cond-> property-key
                                                            many-to-one? (many-to-one-relationship-key-to-physical-column-key))
                                             param-key    (cond->> (param-key entity-key property-key)
                                                            many-to-one? (#(keyword (format "%s-key" (name %)))))
                                             errors       (not-empty (get-in *request* [:entity-param-errors param-key]))]
                                         (cond-> database
                                           (not errors) (assoc-in [entity-key (UUID/fromString (:key uri-parameters)) column-key] (get-in *request* [:entity-params param-key])))))
                                     (target-entity-database entity-key uri-parameters)
                                     (inputtable-property-keys entity-key)))]
      (if (not-empty (get-in *request* [:entity-param-errors]))
        (edit-view entity-key (get-in database [entity-key (UUID/fromString (:key uri-parameters))]))
        (do (save! @database-schema database *transaction*)
            (layout (string/capitalize (dog-mission/translate :update-view-title (dog-mission/translate entity-key)))
                    (javascript-tag (<< "$.crossplane.goToWithMethodAndParams('~(to-uri (<< \"/~(name entity-key)\"))', 'get', ~(json/write-str (base64-decode (get-in *request* [:params :index-params]))));"))))))))

(defn destroy-controller
  [entity-key uri-parameters]
  (layout (string/capitalize (dog-mission/translate :destroy-view-title (dog-mission/translate entity-key)))
          (list [:p "destroy"]
                (link-to-with-method-and-params {:class "btn btn-default"} (to-uri (<< "/~(name entity-key)")) :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back))))))

;; Rouring.


     (pagination-item-control "&raquo;" (< page page-count) false page-count)]))

(defn search-condition-panel
  [entity-class-key & [params]]
  [:div.panel.panel-default
   [:div.panel-heading
    [:div.panel-title (string/capitalize (dog-mission/translate :search-condition))]]
