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

Scope sort and order params by association #471

Closed
micapam opened this issue Feb 16, 2016 · 5 comments
Closed

Scope sort and order params by association #471

micapam opened this issue Feb 16, 2016 · 5 comments

Comments

@micapam
Copy link

micapam commented Feb 16, 2016

Repro steps:

  • Given two models, Foo and Bar, where Foo has many Bars
  • Bar has a 'name' attribute
  • Dashboards set up with has many relationship defined
  • Browse to show page for an instance of Foo that has three Bar instances
  • Observe the order of the three Bar instances, then click on the 'name' header
  • Page reloads with query string modified e.g. direction=asc&order=name

Expected:

  • Bar instances sorted by name

Actual:

  • Sort order is unchanged

Thoughts:

  • Given that it's possible to have multiple has many associations, it's not enough for the query string to specify 'direction' and 'order'. These arguments need to be scoped to the association e.g. 'order[bar]' or 'bar[order]' or something like that.
@micapam
Copy link
Author

micapam commented Feb 16, 2016

(Please let me know your thoughts & preferences on that final point - how to handle multiple has many relationships - and I'd be happy to create a PR to fix this.)

@micapam
Copy link
Author

micapam commented Mar 3, 2016

Ready & willing to fix this myself & raise a PR. Just want core team's input on preferred naming for params. Anyone?

@c-lliope
Copy link
Contributor

c-lliope commented Mar 8, 2016

Hey, @micapam - sorry for the late response. I think naming the params order[bar] and direction[bar] is a good approach. Feel free to open a PR; otherwise I'll figure out a milestone for this.

@a-m-zill
Copy link

Hello.
Short question. Is this problem on the way to solve?
I run in this problem in my current project.

Thx.

@getaaron
Copy link

Is this a dupe of #265?

@carlosramireziii carlosramireziii changed the title Ordering is broken for has_many table on show pages Scope sort and order params by association Mar 7, 2017
rnice01 added a commit to rnice01/administrate that referenced this issue Oct 8, 2017
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
rnice01 added a commit to rnice01/administrate that referenced this issue Oct 8, 2017
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
rnice01 added a commit to rnice01/administrate that referenced this issue Oct 8, 2017
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
rnice01 added a commit to rnice01/administrate that referenced this issue Oct 8, 2017
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
rnice01 added a commit to rnice01/administrate that referenced this issue Oct 22, 2017
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
rnice01 added a commit to rnice01/administrate that referenced this issue Oct 28, 2017
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
rnice01 added a commit to rnice01/administrate that referenced this issue Dec 12, 2017
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
rnice01 added a commit to rnice01/administrate that referenced this issue Dec 15, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants