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

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

Closed
edwinramirez opened this issue Sep 13, 2012 · 5 comments
Assignees

Comments

@edwinramirez
Copy link

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
Copy link
Collaborator

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
Copy link
Collaborator

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

@mceachen
Copy link
Collaborator

released 3.6.1.

@edwinramirez
Copy link
Author

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
Copy link
Collaborator

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants