Fix users list sorting #310
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the default order of the users list by the
member_uid.ActiveRecord doesn't notice that we need to join with
membersin two parts of the ActiveRecord::Relation that we're building and it joins it two times adding an alias calledmembers_users, instead of joining that table just once.As the constraint on the
organization_idwas referencing themembers_userstable this wasn't picked up by Postgres while joining the tables. Specifically, when joininguserswithmembers, thus returning all members of a user, regardless of their organization.So far, the query that gets executed from the users controlle is (See https://github.com/coopdevs/timeoverflow/blob/develop/app/controllers/users_controller.rb#L7):
With this changes it becomes: