Skip to content

Commit e6b4115

Browse files
committed
Added support for ordering fields
1 parent 7207b23 commit e6b4115

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

packages/ar/ar_mode.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,16 @@ def list_model(out, ar, model_id, verbosity = nil)
110110
else
111111
pt = PrinTable.new
112112

113-
puts "verbosity: #{verbosity}"
113+
model_class = model[:class_name]
114+
model_example = model_class.new
114115

115-
out.puts pt.print(model[:class_name].new.filter_fields(verbosity), model[:class_name].all.map { |instance| instance.flatten_fields(verbosity) }, :db)
116+
object_query = if model_example.order_fields.nil? or model_example.order_fields.empty?
117+
-> { model_class.all }
118+
else
119+
-> { model_class.order(*model_example.order_fields) }
120+
end
121+
122+
out.puts pt.print(model[:class_name].new.filter_fields(verbosity), (object_query.call).map { |instance| instance.flatten_fields(verbosity) }, :db)
116123
end
117124
end
118125
end

packages/ar/ar_ns.rb

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def lookup(model_id)
3636
end
3737

3838
module ActiveRecordBaseProxy
39+
def order_fields
40+
[ :id ]
41+
end
42+
3943
def core_fields
4044
[ :id ]
4145
end

packages/ar_example/ar_example.rb

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class ExampleBase < ActiveRecord::Base
3636
self.abstract_class = true
3737
establish_connection DEFAULT_CONNECTION
3838

39+
def order_fields
40+
[ :rowid ]
41+
end
42+
3943
def core_fields
4044
[ :rowid ]
4145
end

0 commit comments

Comments
 (0)