March 26th, 2012 08:12   |   Category: Ruby on Rails

Rails 2.x

Right.find_by_site_id_and_user_id(Site.find(1), User.new)
SELECT * FROM `rights` 
WHERE (`rights`.`site_id` = 1 AND `rights`.`user_id` = NULL) 
LIMIT 1

Rails 3.x

Right.find_by_site_id_and_user_id(Site.find(1), User.new)
SELECT `rights`.* FROM `rights` 
WHERE `rights`.`site_id` = 1 AND `rights`.`user_id` IS NULL 
LIMIT 1

If there are some records which user_id column is NULL, then, it is obvious that we’ll have some problems.