-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Order attributes by association if it exists #999
Order attributes by association if it exists #999
Conversation
e9b9f98
to
72a5bd6
Compare
relation. | ||
left_joins(attribute.to_sym). | ||
group(:id). | ||
reorder("COUNT(#{attribute}.id) #{direction}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
def order_by_count(relation) | ||
relation. | ||
left_joins(attribute.to_sym). | ||
group(:id). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
|
||
def order_by_count(relation) | ||
relation. | ||
left_joins(attribute.to_sym). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
72a5bd6
to
5054c7e
Compare
I'm not sure if I have completely missed the mark or not with these changes for #471 would love some feedback so I can make changes as needed and add specs as well. |
@nickcharlton |
f5e3066
to
dadf9f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good! There's a couple of Hound comments and I left a couple, too.
Adding an order clause to the relation for an associated attribute was having no effect on the dashboard's sorting. When the order is applied, the current relation will check if the attribute is an association and reorder by count on the attribute's id column or on the relation's {attribute}_id column following the Rails convention of naming FK columns. The relation order method was changed to reorder to override any default scoping that may exist for the relation. thoughtbot#471
46f160b
to
564a86e
Compare
Thanks! I'm going to merge this as the two CI failures are around elsewhere, too. |
Awesome, thanks for all the help! |
Adding an order clause to the relation for an associated attribute was having no effect on the dashboard's sorting. When the order is applied, the current relation will check if the attribute is an association and reorder by count on the attribute's id column or on the relation's {attribute}_id column following the Rails convention of naming FK columns. The relation order method was changed to reorder to override any default scoping that may exist for the relation.
#471