Joshua Muheim
2006-Jan-31 15:18 UTC
[Rails] Habtm: I can create the same relation more than 1x!
Hi all I have a DiscJockey and a Member model, each of them reference each other using habtm. josh $ script/server>> m=Member.find 1 >> dj=DiscJockey.find 1 >> m.disc_jockeys << dj >> m.disc_jockeys << dj >> m.disc_jockeys << djNow I have 3 relations in the DB! Is this normal? Shouldn''t there an error occur, that I can only add the object a single time? If it IS normal - how can I prevent it from adding it more than once? Thanks a lot, Josh -- Posted via http://www.ruby-forum.com/.
Joshua Muheim
2006-Jan-31 15:44 UTC
[Rails] Re: Habtm: I can create the same relation more than 1x!
OK, found the following: http://thread.gmane.org/gmane.comp.lang.ruby.rails/14842 But the reply I don''t understand: "Compound primary keys in your rel table." What does that mean? Thanks. -- Posted via http://www.ruby-forum.com/.
Joshua Muheim
2006-Jan-31 15:52 UTC
[Rails] Re: Habtm: I can create the same relation more than 1x!
I just remarked that the uniq option ignores duplicate relationships, but you still can add as many duplicates as you wish. And:>> m = Member.find 1 >> d = DiscJockey.find 1 >> m.disc_jockeys.push d >> m.disc_jockeys.push d >> m.disc_jockeys.size # 2 >> m.reload >> m.disc_jockeys.size # 1This can''t be no bug, can it? -- Posted via http://www.ruby-forum.com/.