                                       ["select_latest_report"]]]
 
                                     :events
-                                    ["in" "report"
-                                     ["extract" "latest_report_hash"
-                                      ["select_latest_report"]]]
+                                    ["in" "report_id"
+                                     ["extract" "latest_report_id"
+                                      ["select_latest_report_id"]]]
 
                                     (throw (IllegalArgumentException.
                                             (tru "Field 'latest_report?' not supported on endpoint ''{0}''" entity))))]

                                            :field :environments.environment}
                             "latest_report?" {:type :boolean
                                               :queryable? true
                                               :query-only? true}}
               :selection {:from [[:resource_events :events]]
                           :join [:reports
                                  [:= :events.report_id :reports.id]]

               :alias "latest_report"
               :subquery? false
               :source-table "latest_report"}))

(def latest-report-id-query
  "Usually used as a subquery of reports"
  (map->Query {:projections {"latest_report_id" {:type :bigint
                                                 :queryable? true
                                                 :field :certnames.latest_report_id}}
               :selection {:from [:certnames]}
               :alias "latest_report_id"
               :subquery? false
               :source-table "latest_report_id"}))

(def environments-query
  "Basic environments query, more useful when used with subqueries"
