Skip to content

Commit

Permalink
Only quote table/column names for active record
Browse files Browse the repository at this point in the history
  • Loading branch information
rnestler committed Oct 13, 2023
1 parent 1292131 commit 51cf5a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/rails_admin/abstract_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,19 @@ def model
end

def quoted_table_name
model.quoted_table_name
if adapter == :active_record
model.quoted_table_name
else
table_name
end
end

def quote_column_name(name)
model.connection.quote_column_name(name)
if adapter == :active_record
model.connection.quote_column_name(name)
else
name
end
end

def to_s
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/rails_admin/main_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def get(action, params)
context 'using mongoid, not supporting joins', mongoid: true do
it 'gives back the remote table with label name' do
controller.params = {sort: 'team', model_name: 'players'}
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to match(sort: /.players.\..team_id./, sort_reverse: true)
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to match(sort: /.?players.?\..?team_id.?/, sort_reverse: true)
end
end

context 'using active_record, supporting joins', active_record: true do
it 'gives back the local column' do
controller.params = {sort: 'team', model_name: 'players'}
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to match(sort: /.teams.\..name./, sort_reverse: true)
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to match(sort: /.?teams.?\..?name.?/, sort_reverse: true)
end
end
end
Expand Down

0 comments on commit 51cf5a4

Please sign in to comment.