hangonsoft-GANU6spQydw@public.gmane.org
2005-Jan-28 18:39 UTC
callback buggy with associated records manipulations...severe no?
hi, i tried to reproduce the bug i was talking about earlier...it''s quite easy (as i do not get a lot of echos from the community) 1/ i made a new project 2/created a new DB with 3 tables : authors (name,id) books (name,id) and authors_books(author_id,book_id) 3/ created 2 MVC with the scaffold generator : ./script/generate scaffold author ./script/generate scaffold book 4/ added ''has_and_belongs_to_many :books'' in author.rb 5/added ''has_and_belongs_to_many :authors'' in book.rb 6/ added this in author.rb to achieve auto linking of a new author to every book of the DB: after_save :linktoeverybook def linktoeverybook self.books<<Book.find_all end 7/launched webrick 8/ entered a few books in the DB via the rails app 9/ created my first author.... RESULT: looking at the log i can see that records are created inside the join table between my author and all the books....BUT ITS DONE 6 TIMES...the new author is joined 6 TIMES to every book... even WEIRDER: there''s books update SQL request everywhere....????? every book is updated with it''s own datas (the name in that case)... I do not get a lot of echo for that bug....i don''t think it''s relative to my config (osx, mysql4.1)....it stopped the developement of my app...because i have certain action that executes more than 300 request or much more.... weirder again: it''s the same with every type of built in rails callback...but the faulty loops iteration number is not the same...sometimes it iterates 6 times...sometimes 3 times.... HELPPPPPPPPPP!!!!!!!! :) AM I DOING SOMETHING WRONG?
Duane Johnson
2005-Jan-29 02:04 UTC
Re: callback buggy with associated records manipulations...severe no?
Hangonsoft, I followed your instructions and was indeed able to duplicate the bug. I''m not enough of a rails guru to be able to find the real source of the problem and fix it; however, I was able to write a work-around for now. You can use this code instead: def linktoeverybook Book.find_all.each do |book| connection.insert "INSERT INTO authors_books (author_id, book_id) VALUES (''#{self.id}'', ''#{book.id}'')" end end It''s ugly, but at least it works. If you haven''t already, submit a ticket to http://dev.rubyonrails.com with the detailed description you gave us in this mailing list. Take care, Duane Johnson (canadaduane)
Michael Koziarski
2005-Jan-30 00:51 UTC
Re: callback buggy with associated records manipulations...severe no?
> 1/ i made a new project > 2/created a new DB with 3 tables : authors (name,id) books (name,id) and > authors_books(author_id,book_id) > 3/ created 2 MVC with the scaffold generator : > ./script/generate scaffold author > ./script/generate scaffold book > 4/ added ''has_and_belongs_to_many :books'' in author.rb > 5/added ''has_and_belongs_to_many :authors'' in book.rb > 6/ added this in author.rb to achieve auto linking of a new author to every book > of the DB: > > after_save :linktoeverybook > def linktoeverybook > self.books<<Book.find_all > end > > 7/launched webrick > 8/ entered a few books in the DB via the rails app > 9/ created my first author.... > > RESULT: > looking at the log i can see that records are created inside the join table > between my author and all the books....BUT ITS DONE 6 TIMES...the new author is > joined 6 TIMES to every book... > > even WEIRDER: there''s books update SQL request everywhere....????? > every book is updated with it''s own datas (the name in that case)... > > I do not get a lot of echo for that bug....i don''t think it''s relative to my > config (osx, mysql4.1)....it stopped the developement of my app...because i > have certain action that executes more than 300 request or much more.... > > weirder again: it''s the same with every type of built in rails callback...but > the faulty loops iteration number is not the same...sometimes it iterates 6 > times...sometimes 3 times....I''d second duane''s suggestion to file a ticket at dev.rubyonrails.org about this. If you''re not able to do it, let me know and I''ll file it. I can reproduce this too.> HELPPPPPPPPPP!!!!!!!! :) > > AM I DOING SOMETHING WRONG?No, what you''re trying to do seems fine. Apart from the shouting at the end ;)> _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
hangonsoft-GANU6spQydw@public.gmane.org
2005-Jan-30 13:33 UTC
Re: callback buggy with associated records manipulations...severe no?
with all these new comers to the rails community (which is sooo cool) it''s sometimes difficult to be heard among all these messages ...that''s why i ended my mail SHOUTING :D ticket posted... thanks michael Selon Michael Koziarski <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > 1/ i made a new project > > 2/created a new DB with 3 tables : authors (name,id) books (name,id) and > > authors_books(author_id,book_id) > > 3/ created 2 MVC with the scaffold generator : > > ./script/generate scaffold author > > ./script/generate scaffold book > > 4/ added ''has_and_belongs_to_many :books'' in author.rb > > 5/added ''has_and_belongs_to_many :authors'' in book.rb > > 6/ added this in author.rb to achieve auto linking of a new author to every > book > > of the DB: > > > > after_save :linktoeverybook > > def linktoeverybook > > self.books<<Book.find_all > > end > > > > 7/launched webrick > > 8/ entered a few books in the DB via the rails app > > 9/ created my first author.... > > > > RESULT: > > looking at the log i can see that records are created inside the join table > > between my author and all the books....BUT ITS DONE 6 TIMES...the new > author is > > joined 6 TIMES to every book... > > > > even WEIRDER: there''s books update SQL request everywhere....????? > > every book is updated with it''s own datas (the name in that case)... > > > > I do not get a lot of echo for that bug....i don''t think it''s relative to > my > > config (osx, mysql4.1)....it stopped the developement of my app...because i > > have certain action that executes more than 300 request or much more.... > > > > weirder again: it''s the same with every type of built in rails > callback...but > > the faulty loops iteration number is not the same...sometimes it iterates 6 > > times...sometimes 3 times.... > > I''d second duane''s suggestion to file a ticket at dev.rubyonrails.org > about this. If you''re not able to do it, let me know and I''ll file > it. > > I can reproduce this too. > > > HELPPPPPPPPPP!!!!!!!! :) > > > > AM I DOING SOMETHING WRONG? > > No, what you''re trying to do seems fine. Apart from the shouting at the end > ;) > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Cheers > > Koz > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Victor Jalencas
2005-Jan-30 18:33 UTC
Re: callback buggy with associated records manipulations...severe no?
I''ve also been bit by this bug, but didn''t realize it was the same until a few moments ago. The example with books that you posted made me realize it, since I''m using books for my app too. In my case, since I''ve set up a primary key in the join table, I was receiving ''duplicate entry'' exceptions and thought that I was doing something wrong. What I''ve also observed is that if I run the code interactively from the console, it runs without errors. I was a bit clueless until I read your mail. Victor hangonsoft-GANU6spQydw@public.gmane.org wrote:> hi, > > i tried to reproduce the bug i was talking about earlier...it''s quite easy > (as i do not get a lot of echos from the community) > > > 1/ i made a new project > 2/created a new DB with 3 tables : authors (name,id) books (name,id) and > authors_books(author_id,book_id) > 3/ created 2 MVC with the scaffold generator : > ./script/generate scaffold author > ./script/generate scaffold book > 4/ added ''has_and_belongs_to_many :books'' in author.rb > 5/added ''has_and_belongs_to_many :authors'' in book.rb > 6/ added this in author.rb to achieve auto linking of a new author to every book > of the DB: > > after_save :linktoeverybook > def linktoeverybook > self.books<<Book.find_all > end > > 7/launched webrick > 8/ entered a few books in the DB via the rails app > 9/ created my first author.... > > RESULT: > looking at the log i can see that records are created inside the join table > between my author and all the books....BUT ITS DONE 6 TIMES...the new author is > joined 6 TIMES to every book... > > even WEIRDER: there''s books update SQL request everywhere....????? > every book is updated with it''s own datas (the name in that case)... > > > > > I do not get a lot of echo for that bug....i don''t think it''s relative to my > config (osx, mysql4.1)....it stopped the developement of my app...because i > have certain action that executes more than 300 request or much more.... > > > weirder again: it''s the same with every type of built in rails callback...but > the faulty loops iteration number is not the same...sometimes it iterates 6 > times...sometimes 3 times.... > > > HELPPPPPPPPPP!!!!!!!! :) > > AM I DOING SOMETHING WRONG? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
hangonsoft-GANU6spQydw@public.gmane.org
2005-Feb-03 18:01 UTC
Re: callback buggy with associated records manipulations...severe no?
Ticket 563... tried every solution to bypass that bug but no one seems to work... sometimes i just can get a lowered faulty iteration number (2 or 3 iterations instead of 6) take a look at the rails code but seems to be beyond my skills with ruby :( david!! we need help :D> On Sun, 30 Jan 2005 14:33:58 +0100, hangonsoft-GANU6spQydw@public.gmane.org > <hangonsoft-GANU6spQydw@public.gmane.org> wrote: > > with all these new comers to the rails community (which is sooo cool) it''s > > sometimes difficult to be heard among all these messages ...that''s why i > ended > > my mail SHOUTING :D > > No worries ;) > > > ticket posted... > > What''s the number? I''ll have a look at it tonight if I get the chance. > > > thanks michael > > > > Selon Michael Koziarski <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > 1/ i made a new project > > > > 2/created a new DB with 3 tables : authors (name,id) books (name,id) > and > > > > authors_books(author_id,book_id) > > > > 3/ created 2 MVC with the scaffold generator : > > > > ./script/generate scaffold author > > > > ./script/generate scaffold book > > > > 4/ added ''has_and_belongs_to_many :books'' in author.rb > > > > 5/added ''has_and_belongs_to_many :authors'' in book.rb > > > > 6/ added this in author.rb to achieve auto linking of a new author to > every > > > book > > > > of the DB: > > > > > > > > after_save :linktoeverybook > > > > def linktoeverybook > > > > self.books<<Book.find_all > > > > end > > > > > > > > 7/launched webrick > > > > 8/ entered a few books in the DB via the rails app > > > > 9/ created my first author.... > > > > > > > > RESULT: > > > > looking at the log i can see that records are created inside the join > table > > > > between my author and all the books....BUT ITS DONE 6 TIMES...the new > > > author is > > > > joined 6 TIMES to every book... > > > > > > > > even WEIRDER: there''s books update SQL request everywhere....????? > > > > every book is updated with it''s own datas (the name in that case)... > > > > > > > > I do not get a lot of echo for that bug....i don''t think it''s relative > to > > > my > > > > config (osx, mysql4.1)....it stopped the developement of my > app...because i > > > > have certain action that executes more than 300 request or much > more.... > > > > > > > > weirder again: it''s the same with every type of built in rails > > > callback...but > > > > the faulty loops iteration number is not the same...sometimes it > iterates 6 > > > > times...sometimes 3 times.... > > > > > > I''d second duane''s suggestion to file a ticket at dev.rubyonrails.org > > > about this. If you''re not able to do it, let me know and I''ll file > > > it. > > > > > > I can reproduce this too. > > > > > > > HELPPPPPPPPPP!!!!!!!! :) > > > > > > > > AM I DOING SOMETHING WRONG? > > > > > > No, what you''re trying to do seems fine. Apart from the shouting at the > end > > > ;) > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > -- > > > Cheers > > > > > > Koz > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > -- > Cheers > > Koz >