diff --git a/lib/ransack/nodes/sort.rb b/lib/ransack/nodes/sort.rb index 923558351..b297a594c 100644 --- a/lib/ransack/nodes/sort.rb +++ b/lib/ransack/nodes/sort.rb @@ -31,7 +31,7 @@ def valid? end def name=(name) - @name = name + @name = context.ransackable_alias(name) || name context.bind(self, name) end diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 74d83bcde..f7a4ee8cb 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -24,12 +24,19 @@ ) end +class PersonAlias < ActiveRecord::Base + belongs_to :person +end + class Person < ActiveRecord::Base default_scope { order(id: :desc) } belongs_to :parent, class_name: 'Person', foreign_key: :parent_id has_many :children, class_name: 'Person', foreign_key: :parent_id has_many :articles has_many :story_articles + has_many :aliases, class_name: 'PersonAlias' + + ransack_alias :aka, :aliases_name has_many :published_articles, ->{ where(published: true) }, class_name: "Article" @@ -194,6 +201,11 @@ def self.create t.timestamps null: false end + create_table :person_aliases, force: true do |t| + t.integer :person_id + t.string :name + end + create_table :articles, force: true do |t| t.integer :person_id t.string :title