drnic/composite_primary_keys — Issue #78: exists? expands incorrectly when composite keys are strings
Author: sronsiek
Created: 2011-12-11 18:46:31+00:00
State: open

Hi,

I have table with a composite primary key consisting of two varchars.

I've noted that when I call .exists?( id ) with id which is an array
of integers, the resulting sql query expands correctly:

irb(main):019:0> id = [ 1, 2 ]
irb(main):020:0> MyModel.exists?( id )
(0.6ms) SELECT 1 FROM `my_model` WHERE (`my_model`.`key1` = 1 AND `my_model`.`key2` = 2) LIMIT 1
=> false

However, when I pass an array of strings (or a comma separated list of values) it doesn't expand correctly:

irb(main):017:0> id = [ '1', '2' ]
irb(main):020:0> MyModel.exists?( id )
(0.3ms) SELECT 1 FROM `my_model` WHERE (1) LIMIT 1

I want to use exists? instead of find() as the former does not raise exceptions on fail ...