@@ -1521,7 +1521,7 @@ module ForemanRemoteExecution
1521
1521
# We need to make sure, there's a AR relation we'd be searching on, because the class name can't be determined by the
1522
1522
# association name, it needs to be specified explicitly (as a string). Similarly for the foreign key.
1523
1523
has_one :execution_status_object, :class_name => 'HostStatus::ExecutionStatus', :foreign_key => 'host_id'
1524
-
1524
+
1525
1525
# Then we define the searching, the relation is the association name we define on a line above
1526
1526
# :rename key indicates the term user will use to search hosts for a given state, the convention is $feature_status
1527
1527
# :complete_value must be a hash with symbolized keys specifying all possible state values, otherwise the autocompletion
@@ -2391,6 +2391,38 @@ Foreman Webhooks plugin ships with an example "Remote Execution Host Job" templa
2391
2391
2392
2392
You can find all observable events by calling `Foreman::EventSubscribers.all_observable_events` in the Rails console.
2393
2393
2394
+ === How to order by a virtual column
2395
+ _Requires Foreman 3.14 or higher, set `requires_foreman '>= 3.14'` in
2396
+ engine.rb_
2397
+
2398
+ NOTE: The following assumes usage of:
2399
+ * `resource_scope_for_index` in the API controller's index action.
2400
+ * `resource_base_with_search` or `resource_base_search_and_page` in the UI controller's index action.
2401
+
2402
+ Starting Foreman 3.14, both UI and API controllers can order by virtual columns.
2403
+ This is achieved by using the `select_<virtual_column>` scope in the model.
2404
+ The scope should return the virtual column in the select statement.
2405
+
2406
+ [source, ruby]
2407
+ ....
2408
+ # app/models/model.rb
2409
+ scope :select_virtual_column, lambda {
2410
+ select("model_table.*,(column,column2) as virtual_column")
2411
+ }
2412
+ ....
2413
+
2414
+ NOTE: In case your UI controller doesn't use `resource_base_with_search` or `resource_base_search_and_page`,
2415
+ you can use the `wrap_for_virt_column_select` method in the controller to order by virtual columns.
2416
+
2417
+ [source, ruby]
2418
+ ....
2419
+ # app/controllers/plugin/controller.rb
2420
+ def index
2421
+ # Model can be already scoped by other means
2422
+ @objects = wrap_for_virt_column_select(Model)
2423
+ end
2424
+ ....
2425
+
2394
2426
[[translating]]
2395
2427
== Translating
2396
2428
0 commit comments