Fernando Perez
2008-Apr-25 19:48 UTC
Why is Rails making 2 SELECT queries when updating user info
Hi, My User model has been generated using the restful_authentication generator. When I submit data to the update action of the users_controllers, I see that Rails makes the following queries which are unnecessary: BEGIN SELECT * FROM `users` WHERE (LOWER(users.login) = ''fernando'' AND users.id <> 2) LIMIT 1 SELECT * FROM `users` WHERE (LOWER(users.email) = ''fernando'' AND users.id <> 2) LIMIT 1 UPDATE ''users'' ... COMMIT Is there something I have made that creates these two SELECT queries? I really don''t understand where it is coming from. -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Apr-25 20:06 UTC
Re: Why is Rails making 2 SELECT queries when updating user info
On 25 Apr 2008, at 20:48, Fernando Perez wrote:> > Hi, > > My User model has been generated using the restful_authentication > generator. When I submit data to the update action of the > users_controllers, I see that Rails makes the following queries which > are unnecessary: > > BEGIN > SELECT * FROM `users` WHERE (LOWER(users.login) = ''fernando'' AND > users.id <> 2) LIMIT 1 > SELECT * FROM `users` WHERE (LOWER(users.email) = ''fernando'' AND > users.id <> 2) LIMIT 1 > UPDATE ''users'' ... > COMMIT >Have you got some validations that might cause this ?(in particular validates_uniqueness_of) Fred> > Is there something I have made that creates these two SELECT > queries? I > really don''t understand where it is coming from. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Fernando Perez
2008-Apr-25 20:09 UTC
Re: Why is Rails making 2 SELECT queries when updating user
That''s exactly the case! I tested by removing the validation, and the 2 SELECT didn''t happen. Thank your very much for your assitance. -- 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 -~----------~----~----~----~------~----~------~--~---