Skip to content

Commit

Permalink
Add table name on order clause to prevent ambiguous column name
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatasrancan committed Oct 16, 2017
1 parent 84cdf55 commit c0895f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/administrate/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(attribute = nil, direction = nil)

def apply(relation)
if relation.columns_hash.keys.include?(attribute.to_s)
relation.order("#{attribute} #{direction}")
relation.order("#{relation.table_name}.#{attribute} #{direction}")
else
relation
end
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/administrate/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

ordered = order.apply(relation)

expect(relation).to have_received(:order).with("name asc")
expect(relation).to have_received(:order).with("table_name.name asc")
expect(ordered).to eq(relation)
end

Expand All @@ -47,7 +47,7 @@

ordered = order.apply(relation)

expect(relation).to have_received(:order).with("name desc")
expect(relation).to have_received(:order).with("table_name.name desc")
expect(ordered).to eq(relation)
end
end
Expand Down Expand Up @@ -138,6 +138,6 @@
end

def relation_with_column(column)
double(columns_hash: { column.to_s => :column_info })
double(columns_hash: { column.to_s => :column_info }, table_name: 'table_name')
end
end

0 comments on commit c0895f1

Please sign in to comment.