Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Prepending when using Deterministic ordering with Polymorphic hierarchies updates position of only the same type #20

edwinramirez opened this Issue Sep 13, 2012 · 5 comments


None yet
2 participants

Hello, I'm having a problem using Deterministic ordering with Polymorphic hierarchies with STI.
In my project I'm moving elements of different types. When I move an element in between it's siblings the resulting SQL statement updates the sort_order column of only elements of the same type.

For example:

  • Element A is type "Text" with "sort_order" 1
  • Element B is type "Group" with "sort_order" 2
  • Element C is type "Photo" with "sort_order" 3
  • All of these elements have the same parent.

If I prepend Element A to C then the resulting SQL statement is:
UPDATE elements SET sort_order = sort_order - 1 WHERE elements.type IN ('Photo') AND (parent_id = ## AND sort_order <= 2))

So, only elements type "Photo" have their "sort_order" value updated resulting in:
Element C remains with a "sort_order" value of 3 while element A and B now have a "sort_order" value of 2.

How can I override this behavior and have that moving an element updates the order of all siblings before or after it?


mceachen commented Sep 14, 2012

This seems like a bug! We need to make a breaking test, then fix the implementation. I'll try to get to this soon. If you send me a pull request with either the test, or the bugfix, that would certainly be helpful.

@ghost ghost assigned mceachen Sep 15, 2012


mceachen commented Sep 17, 2012

Pushed new branch with fix. This will be addressed in v3.6.1.


mceachen commented Sep 17, 2012

released 3.6.1.

@mceachen mceachen closed this Sep 17, 2012

Hey thank you so much man. Great job. And I'm soooo sorry I couldn't help sending a breaking test at least but I'm such a noob in ruby on rails that I couldn't even get a decent test in order. I'm surprised I actually detected a bug!


mceachen commented Sep 18, 2012

You're welcome, and thanks for taking the time to writing this up in the first place!

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