Im trying to establish relationships in a many to many table. When I create a user, I do this to insert the different relationships between the user and sports: c.sports<<Sport.find_all_by_name(params[:sports]) where c is the user. The problem is, when I edit this user, and lets say he adds a sport, I can''t use this because I get an error saying that some records already exist since its not only adding the new records but also all the old records again. What is the best way to do an updating like this is rails? Should I just delete all the records associated with the user and add them in again? -- Posted via http://www.ruby-forum.com/.
Check out http://hasmanythrough.rubyforge.org/ --- Eric Gross <tennisbum2002@hotmail.com> wrote:> Im trying to establish relationships in a many to many table. > > When I create a user, I do this to insert the different relationships > between the user and sports: > > > c.sports<<Sport.find_all_by_name(params[:sports]) > > where c is the user. The problem is, when I edit this user, and lets say > he adds a sport, I can''t use this because I get an error saying that > some records already exist since its not only adding the new records but > also all the old records again. > > What is the best way to do an updating like this is rails? > > Should I just delete all the records associated with the user and add > them in again? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Eric Gross
2006-Jul-31 20:52 UTC
[Rails] Re: updating records in a many-to-many relationship
I took a look at that site, its doesnt talk about how to handle updating of data with ruby''s built in many-to-many feature, the one where you set a table A_B for table A and B. Bala Paranj wrote:> Check out http://hasmanythrough.rubyforge.org/-- Posted via http://www.ruby-forum.com/.