要打电话给你希望你的CA一起去的方法:
ActiveRecord::Base.connection.send(:table_structure, "projects")
但我认为更好的办法是使用columns_hash
获取有关表结构的最详细的信息:
Get the columns for a table as a hash, key is the column name value is the column object.
Project.columns_hash
用法:假设您想获得有关id
列的信息:
Project.columns_hash['id']
#=> #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x007fda9e48ce90
# @array=false,
# @cast_type=#<ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer:0x007fda9bda2e88 @limit=nil, @precision=nil, @range=-2147483648...2147483648, @scale=nil>,
# @default=nil,
# @default_function="nextval('users_id_seq'::regclass)",
# @name="id",
# @null=false,
# @sql_type="integer">
也有columns
Returns an array of column objects for the table associated with this class.
和column_names
:
Returns an array of column names as strings.
Project.columns
Project.column_names
见full list of methods in documentation。
'NoMethodError:未定义的方法 'table_structure' 为#'使用发送 –
@Deepak OP使用SQLite3 :) –
ahh。好的明白了.. –