Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect ransack_alias when sorting related tables #1084

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ransack/nodes/sort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def valid?
end

def name=(name)
@name = name
@name = context.ransackable_alias(name) || name
context.bind(self, name)
end

Expand Down
12 changes: 12 additions & 0 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down