Özgün Koyun Özgün Koyun

Dynamic "find_by" methods (Rails 2.x vs Rails 3.x)

  ruby rails

Rails 2.x

Right.find_by_site_id_and_user_id(Site.find(1), User.new)

Generated query:

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)  

Generated query:

SELECT `rights`.* FROM `rights` 
WHERE `rights`.`site_id` = 1 AND `rights`.`user_id` IS NULL 
LIMIT 1