我已经编写了一个使用传统MySQL数据库的Rails应用程序。一个表包含这一领域Rails无法识别传统数据库上的布尔字段
CREATE TABLE `articles` (
`active` tinyint(3) unsigned NOT NULL DEFAULT '0',
);
我固定
t.boolean "active", :default => false
但轨方案不承认那场布尔
[1] pry(main)> Article.new.active.class
=> Fixnum
这将创建一个验证问题因为我在我的课上有这个验证器
class Article < ActiveRecord::Base
validates_inclusion_of :active, :in => [true, false]
end
当我分配布尔值到该字段它们转换为Fixnum对象和验证失败,消息"1 is not included in the list"
如果我生成具有相同的模型生成的SQL代码是
CREATE TABLE `posts` (
`active` tinyint(1) DEFAULT NULL,
)
而且一切新的应用正常工作:
[1] pry(main)> Article.new.active.class
=> FalseClass
有没有什么办法让视为布尔我的遗产列(可能不运行迁移)?
我也会允许'true'&'false',除非它们根本不工作(即,试图在该列中插入“true”或“false”给出不正确的结果)。 – Romain 2012-07-26 12:14:36