Could ActiveRecord add some comments when create table

6 views
Skip to first unread message

Wu Junchen

unread,
Mar 12, 2008, 3:00:33 AM3/12/08
to rubyonra...@googlegroups.com
Could ActiveRecord add some comments for a column when create a
table?For example use some sentence like this:

create_table :blogs do |t|
t.string, :blog_title, :limit=>100,:null=>false, :comment=>'my blog
title'
end

After do this,I can use the comment instead of the human name of
column,it's more suitable.
--
Posted via http://www.ruby-forum.com/.

Mark Bush

unread,
Mar 12, 2008, 4:34:14 AM3/12/08
to rubyonra...@googlegroups.com
Wu Junchen wrote:
> Could ActiveRecord add some comments for a column when create a
> table?

Column comments are not part of the table as such and not available in
all databases. The normal solution for this sort of requirement is to
encode it yourself. In your migration, use something like:

class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name
t.datetime :dob
t.timestamps
end
if config[RAILS_ENV]['adapter'].match(/oracle|oci/)
execute "comment on column users.name is 'The username of the
user'"
end
end
:

Reply all
Reply to author
Forward
0 new messages