четверг, 15 января 2009 г.

ActiveRecord, boolean и MySQL

Разрабатываю на sqlite3 сайт, выгружаю в mysql на хостинг, и опа, boolean колонки обрабатываются странно на предмет find_by_active(true), точнее в sqlite3 это работает, а в mysql не работает :(
А вот оно что:

Each of the database adapters is responsible for determining how to
handle a boolean column in a way that makes sense for their specific
backend. In the case of PostgreSQL and OpenBase this is trivial,
since these database backends have a boolean type column built-in.
For MySQL - as has been pointed out - booleans are usually handled as
tinyint. The MySQL adapter therefore will default to handle tinyint
columns as booleans. However, this behavior can be changed by
setting MysqlAdapter.emulate_booleans = false.

If you define your schema within rails and give the column a type
of :boolean, then the adapter you are using will create a column of
whatever type makes sense for that database, thus achieving (at least
to this extent) database agnosticism. Beautiful. Sorta brings a
tear to your eye, doesn't it?

-Derrick Spell

Комментариев нет:

Отправить комментарий