Excellent info, this little tibdit helps me, too, coming to Rails for a mod_perl world where everything is dynamically typed (“1” == 1 etc). The typecasting logic of ActiveRecord has been a learning curve.
Anyone know of a more detailed description of how the typecasting workflow works, from ActiveRecord down to the MySQL level? That’d be a super useful document/overview to have. Each layer (app, activerecord, ruby mysql client, mysql itself) will have it’s own concerns on this chain of events.
In certain versions of MySQL, the typecasting can become extremely important, due to strange bugs in MySQL. For instance, if you do something like
“select * from mytable where id > ‘1234’”
and 1234 is an integer column but you’ve put in quotes (i.e. a string) for the query, and it is outside the bounds of the index on id, MySQL will resort to a table scan. i saw this bug wreak havoc on a large rig once, in mod_perl world where the database adapter put quotes around integers.
But that’s just an example of how fully understanding typecasting from top-down can be a really useful thing.