Skip to content

Conversation

@Mirkoffcito
Copy link

@Mirkoffcito Mirkoffcito commented Aug 22, 2021

Added an optional distinct for sorting nested associations with ransack gem, since you have to set .result(distinct: false) for it to work.

For example, given an endpoint where we have many users, and each user can have many posts, and each post have a title column:

  • /users?q[s]=post_title asc should sort all users based on the title of their posts, but it won't work because of (distinct: true).
    But if we set distinct to false, it will sort properly.

This way, when we want to sort with an association, in out controller we would do:

  • respond_with filtered_collection(User.all, false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant