administrate
administrate copied to clipboard
Use reflection table name when ordering on association columns
Ordering on association columns is broken if the associated model uses a non-standard table name. attribute.tableize is not sufficient.
For example, given these models
class Foo < ApplicationRecord
has_one :bar
end
class Bar < ApplicationRecord
self.table_name = "namespace_bars"
belongs_to :foo
end
Administrate::Order assumes that ordering Foos by bar.name should add ORDER BY bars.name when in this case, it should be ORDER BY namespace_bars.name. The reflection contains the table_name, so this is easy to resolve by passing the reflection around to a few more.