-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
acts_as_list methods on has_many through #308
Comments
Hi @lsarni, that's a mind bender. Do you only have a position column on the join table? or also on the links table?
|
I have the And the primary key is requested in quite a few of the list methods defined by the library, for example With the stated workaround I managed to get al the methods working correctly. Maybe, if there isn't an out of the box solution, adding a flag to state that we are working on a join table and include this behaviour could be a good improvement. |
I see, what if you just called the methods directly on the join association: link = update.links.last # Or whatever you want to select
update.update_links.where(link: link).first.move_to_top It's a bit messy, but should do the trick. What do you think? |
I have tried it out, and I get this error:
The same happens for the other methods. |
Shouldn't this be
You need
|
@swanandp you're right, I was missing the It works regardless of whether the scope is It is pretty messy, but it's is exactly what the workaround does so I'm going to keep that on my project so it looks neater. But feel free to close the issue. |
Glad it's working. |
I think the scope should be |
I just noticed that this won't work for |
Instead of using |
I'm using a
has_many through
relationship with a join table, like it was explained in some other issues and Stackoverflow.This is how my models look like:
But if I try to use any of the
acts_as_list
methods like this:I saw this workaround but since it's quite an old post I was wondering if the library has been extended to be usable on this cases.
I made some changes to the workaround so it works with all the methods and had to add a
primary_key
to my join table (since many of the list methods call it):That way instead of doing
list_item.move_higher
I docollection.move_higher(list_item)
.But if there is a built in way of doing this I would much prefer that.
The text was updated successfully, but these errors were encountered: