Hi, I ve got two model, Video and Pack... My Pack model can have multiple Video, and a Video belongs to multiple Pack...So i m doing a join table, Video_Pack... So my Models looks like : Video : ID Name etc. Pack : ID Name etc. Video_Pack Video_id Pack_video I would like to be able to order the video in a Pack... so i guess the best solution is to use the acts_as_lists plugin... This way i will have to use it on the join table, Video_Pack... so i''ve to add to my Video_Pack model, the column Position... right? Right now all of that is in my head, and i ve no idea if i m right or maybe 100% wrong... so if you could give me an hand i ll appreciate a lot, Thanks in advance, Guillaume. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Differenthink wrote:> Hi, > > I ve got two model, Video and Pack... My Pack model can have multiple > Video, and a Video belongs to multiple Pack...So i m doing a join > table, Video_Pack... > So my Models looks like : > > Video : > ID > Name > etc. > > Pack : > ID > Name > etc. > > Video_Pack > Video_id > Pack_video > > I would like to be able to order the video in a Pack... so i guess the > best solution is to use the acts_as_lists plugin... This way i will > have to use it on the join table, Video_Pack... so i''ve to add to my > Video_Pack model, the column Position... right? > > Right now all of that is in my head, and i ve no idea if i m right or > maybe 100% wrong... so if you could give me an hand i ll appreciate a > lot, > > Thanks in advance, > Guillaume.This may not really answer your question, but the join table should be named with the two components in alphabetical order, lower case, and pluralised, so in your case the join table should be called packs_videos and have pack_id, video_id Also i think it''s better to keep all of your id fields in lower case - id, video_id, pack_id : that''s what rails expects so you''ll have to do less configuration stuff. In the model, you need to use the "has_and_belongs_to_many" relationship, ie class Video < ActiveRecord::Base has_and_belongs_to_many :packs ... end class Pack < ActiveRecord::Base has_and_belongs_to_many :videos ... end Once you''ve got this, if you want all the videos from a pack (which you have as @pack for example) you should be able to simply say ask for @pack.videos.sort (i think) for a sorted view of all the videos that belong to that pack. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the tips, anyone for the my acts as list question/problem ? On Jul 24, 8:16 pm, Max Williams <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Differenthink wrote: > > Hi, > > > I ve got two model, Video and Pack... My Pack model can have multiple > > Video, and a Video belongs to multiple Pack...So i m doing a join > > table, Video_Pack... > > So my Models looks like : > > > Video : > > ID > > Name > > etc. > > > Pack : > > ID > > Name > > etc. > > > Video_Pack > > Video_id > > Pack_video > > > I would like to be able to order the video in a Pack... so i guess the > > best solution is to use the acts_as_lists plugin... This way i will > > have to use it on the join table, Video_Pack... so i''ve to add to my > > Video_Pack model, the column Position... right? > > > Right now all of that is in my head, and i ve no idea if i m right or > > maybe 100% wrong... so if you could give me an hand i ll appreciate a > > lot, > > > Thanks in advance, > > Guillaume. > > This may not really answer your question, but the join table should be > named with the two components in alphabetical order, lower case, and > pluralised, so in your case the join table should be called > > packs_videos > and have > pack_id, video_id > > Also i think it''s better to keep all of your id fields in lower case - > id, video_id, pack_id : that''s what rails expects so you''ll have to do > less configuration stuff. > > In the model, you need to use the "has_and_belongs_to_many" > relationship, ie > > class Video < ActiveRecord::Base > has_and_belongs_to_many :packs > ... > end > > class Pack < ActiveRecord::Base > has_and_belongs_to_many :videos > ... > end > > Once you''ve got this, if you want all the videos from a pack (which you > have as @pack for example) you should be able to simply say ask for > @pack.videos.sort (i think) for a sorted view of all the videos that > belong to that pack. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
By the way Max, i m using more that the ID in my join table so habtm is not working... i m using has_many with the through parameters.. so i can name my join table as i want... On Jul 25, 12:05 am, Differenthink <guillaume.mont...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the tips, > anyone for the my acts as list question/problem ? > > On Jul 24, 8:16 pm, Max Williams <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Differenthink wrote: > > > Hi, > > > > I ve got two model, Video and Pack... My Pack model can have multiple > > > Video, and a Video belongs to multiple Pack...So i m doing a join > > > table, Video_Pack... > > > So my Models looks like : > > > > Video : > > > ID > > > Name > > > etc. > > > > Pack : > > > ID > > > Name > > > etc. > > > > Video_Pack > > > Video_id > > > Pack_video > > > > I would like to be able to order the video in a Pack... so i guess the > > > best solution is to use the acts_as_lists plugin... This way i will > > > have to use it on the join table, Video_Pack... so i''ve to add to my > > > Video_Pack model, the column Position... right? > > > > Right now all of that is in my head, and i ve no idea if i m right or > > > maybe 100% wrong... so if you could give me an hand i ll appreciate a > > > lot, > > > > Thanks in advance, > > > Guillaume. > > > This may not really answer your question, but the join table should be > > named with the two components in alphabetical order, lower case, and > > pluralised, so in your case the join table should be called > > > packs_videos > > and have > > pack_id, video_id > > > Also i think it''s better to keep all of your id fields in lower case - > > id, video_id, pack_id : that''s what rails expects so you''ll have to do > > less configuration stuff. > > > In the model, you need to use the "has_and_belongs_to_many" > > relationship, ie > > > class Video < ActiveRecord::Base > > has_and_belongs_to_many :packs > > ... > > end > > > class Pack < ActiveRecord::Base > > has_and_belongs_to_many :videos > > ... > > end > > > Once you''ve got this, if you want all the videos from a pack (which you > > have as @pack for example) you should be able to simply say ask for > > @pack.videos.sort (i think) for a sorted view of all the videos that > > belong to that pack. > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---