Hello all, I''m working on a small Rails site for a game I play that will be used to add new characters. Part of this addition process is choosing what skills the character will have. For this, in MySQL, I have a characters table and a skills table, as well as a characters_skills table that is used as the join table in the habtm relationship between the two. I am presenting the skills in select boxes, which are separated based on the category of the skill. Everything is working well, except for one issue. Due to the nature of this game, skills can be selected multiple times. However, when Rails inserts goes to insert the selected data, it skips the duplicates, e.g. if the selected ids are 1, 1, 2, 3, only 1, 2, and 3 will be written into the join table. Is there perhaps an option to have Rails write duplicates into the table, or am I looking at the whole model incorrectly? Any advice would be appreciated.
> Is there perhaps an option to have Rails write duplicates into the > table, > or am I looking at the whole model incorrectly? Any advice would be > appreciated.That should work. Hard to say why it''s not without seeing your code. But another approach would be to use a has_many :through association with a count attribute in the join model. Then you wouldn''t need to worry about counting multiple rows in the join table. -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.
Not too much going on in the code (I don''t think). Several select boxes in the character view, which look somewhat like this: <% regular_skills SkillCategory.find(:first, :conditions => "name = ''Regular''").skills %> <select id="character_skill_ids" name="character[skill_ids][]"> <%= options_from_collection_for_select(regular_skills, ''id'', ''name'') %> </select> Which is all being saved with the normal create method in the characters_controller (no extra code there from me). I''ll look into your has_many :through suggestion also. Thanks for looking. Matt --- rails@lists.rubyonrails.org wrote:> > Is there perhaps an optionto have Rails write duplicates into the> > table, > > or am I lookingat the whole model incorrectly? Any advice would be> > appreciated. >> That should work. Hard to say why it''s not without seeing your code. But> another approach would be to use a has_many :through association witha> count attribute in the join model. Then you wouldn''t need to worry about> counting multiple rows in the join table. > > -- > Josh Susser >http://blog.hasmanythrough.com> > -- > Posted via http://www.ruby-forum.com/.> _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails>