-
-
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
has_many :through or has_many_and_belongs_to_many support #86
Comments
It works if you use acts_as_list on the join table. For example if you have a |
Alright, I did as you said and when adding items not in the list it does add them at the bottom of the list. However updating the object with a different order doesn't trigger any change in the db ( as seen below). class Playlist < ActiveRecord::Base
has_many :playlist_contents, ->{ order "position"}c
has_many :media, through: :playlist_contents, dependent: :destroy
attr_accessible :medium_ids
end
class PlaylistContent < ActiveRecord::Base
belongs_to :playlist
belongs_to :medium
attr_accessible :position
acts_as_list scope: :playlist
end
irb(main):002:0> p.medium_ids irb(main):003:0> p.medium_ids= [1,2,3] irb(main):004:0> p.reload irb(main):005:0> p.medium_ids irb(main):006:0> p.update_attributes medium_ids: [1,2,3] irb(main):007:0> p.reload irb(main):008:0> p.medium_ids The same thing happens when updating p.playlist_contents_ids. Do you know why that doesn't work, or might you have any code or documentation I can look at to understand why this isn't working? |
When you're executing If you're just trying to move one item you can achieve the automatic list reordering just updating that item's position.
|
I had to remove a post in between, because it was just wrong. I'm trying to do a big update. The user will move around items in the list and click on "Save". |
This might be a little tricky with the way |
I'm closing this for now due to inactivity. |
Hello,
I have not been able to work out how to make this work with a has_many :through association.
The easiest example I can think of is Playlists have many Songs and Songs belong to many Playlists. The position would have to be added to the intermediary table, because the position can be different in different playlists.
Does this gem support those associations?
The text was updated successfully, but these errors were encountered: