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

wrong attribute update #86

Closed
tommybernaciak opened this issue Sep 23, 2014 · 4 comments
Closed

wrong attribute update #86

tommybernaciak opened this issue Sep 23, 2014 · 4 comments

Comments

@tommybernaciak
Copy link

This is very nice gem, but has a liitle bug. Attribute used for ranking is wrongly updated. I found this when implementing some sortable tables in rails. List of users is ordered by position - attribute use by ranked-model. Here is how the table look like:
table1

After taking element with position 15 to 5 every element gets updated, but look what happened to element with position > 15, it gets also added 1 so now there is a break (17th element after 15th, no element with position 16).
table2
After some modification of order it gets really annoying, because you dont know exactly how its going to work.

Another mistake is that it doesnt work for two elements at all. Position is getting max integer and min integer value.

I am using Postgres with Rails 4, if you want to see my implementation I can add link to the project.

@mixonic
Copy link
Contributor

mixonic commented Oct 3, 2014

@tommy-dev ranked-model gets its efficiency gain by not managing position, but instead only providing relative rankings in a large integer space. There is no guarantee there will not be a gap in the ranking.

This should be spelled out pretty clearly at the top of the Readme. It seems here that your ranking column (ranks, not positions) is very tightly clustered. That means a rank rebalance is happening on every change. This is definitely not optimal, maybe this is coming from old data in a position column?

Also, please upload an image without emails addresses, names and phone number.

@tommybernaciak
Copy link
Author

Here is my implementation, based on the readme:
https://github.com/binarapps/sortable-tables
Position is a field used by ranked-model (ranks :position in user model)
My idea was to use this field as a position in the table, so after changing one elements position, other gonna be updated, and the order will be kept. The problem with update is that it doesnt take under consideration the previous position of changed element. In the posted pics you can see that in all elements after 5 position is added, that why there is a gap here.
If it is not going to work like this, please tell me so I will implement sth on my own. I just thought it is good gem for this task, but maybe I didnt understand how it is working.

And dont worry about the images, data is Faker generated so no real personal data is shown here. :)

@mixonic
Copy link
Contributor

mixonic commented Oct 11, 2014

@tommy-dev I remain very uncertain as to what you are trying to do.

ranked models stores a rank in the database. You should not manually be setting the rank. It provides a position attribute (explained on the readme) for reading the position, but this is merely a convenience.

If something is awry, a test or example code would help me understand what you are expecting to happen.

@brendon
Copy link
Owner

brendon commented Jun 4, 2024

There was a bug that may have caused this. It was fixed a long time ago.

@brendon brendon closed this as completed Jun 4, 2024
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

3 participants