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.

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

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.