Skip to content

Commit

Permalink
Fix rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickgramatowski committed Jul 8, 2022
1 parent 837c283 commit d38cd56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/controllers/administrate/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def order
@order ||= Administrate::Order.new(
sorting_attribute,
sorting_direction,
association_attribute: order_by_field(dashboard_attribute(sorting_attribute)),
association_attribute: order_by_field(
dashboard_attribute(sorting_attribute),
),
)
end

Expand Down
7 changes: 5 additions & 2 deletions lib/administrate/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,18 @@ def order_by_id(relation)
def order_by_attribute(relation)
if ordering_by_association_column?(relation)
relation.joins(
attribute.to_sym
attribute.to_sym,
).reorder(Arel.sql(order_by_attribute_query))
else
order_by_id(relation)
end
end

def ordering_by_association_column?(relation)
association_attribute && column_exist?(reflect_association(relation).klass, association_attribute.to_sym)
association_attribute &&
column_exist?(
reflect_association(relation).klass, association_attribute.to_sym
)
end

def column_exist?(table, column_name)
Expand Down

0 comments on commit d38cd56

Please sign in to comment.