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

   "select_nodes" nodes-query
   "select_inactive_nodes" inactive-nodes-query
   "select_latest_report" latest-report-query
   "select_params" resource-params-query
   "select_reports" reports-query
   "select_inventory" inventory-query

               :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"
