【发布时间】:2011-07-17 09:16:00
【问题描述】:
我正在编写 Rails 迁移以创建表:
create_table(TABLE, :options => FEDERATED_TABLE_CONFIG % TABLE) do |table|
table.timestamps
table.string :country_tld
end
结果如下表:
CREATE TABLE `sites` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`country_tld` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=FEDERATED DEFAULT CHARSET=utf8 CONNECTION='mysql://foo:bar@localhost/baz/sites'
可悲的是,我的外国数据源使用老式 Rails updated_on 和 created_on 列作为其时间戳。我当然可以解决这个问题:
create_table(TABLE, :options => FEDERATED_TABLE_CONFIG % TABLE) do |table|
table.datetime :created_on, :updated_on
table.string :country_tld
end
如果有一种简单的方法仍然可以使用时间戳并获得我想要的行为,我很想听听。不,我不认为monkey-patching ActiveRecord::Timestamp 是一种微不足道的做法,因为这只会影响一次迁移。 ;)
【问题讨论】:
标签: ruby-on-rails