Skip to content

Sort doesn't work in case if there is join on same table  #936

@chopraanmol1

Description

@chopraanmol1
Comment.joins(:person).ransack(article_title_cont: 'aven',s: 'person_salary desc').result

The above code doesn't work and raise the following exception

ActiveRecord::StatementInvalid:
       SQLite3::SQLException: no such column: people_comments.salary: SELECT "comments".* FROM "comments" INNER JOIN "people" ON "people"."id" = "comments"."person_id" LEFT OUTER JOIN "articles" ON "articles"."id" = "comments"."article_id" AND ('default_scope' = 'default_scope') WHERE ("articles"."title" LIKE '%aven%')  ORDER BY "people_comments"."salary" DESC

Alternate which works are as follow

Comment.ransack(article_title_cont: 'aven',s: 'person_salary desc').result
Comment.joins(:person).ransack(s: 'person_salary desc', article_title_cont: 'aven').result

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions