당신이 갈 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 : –
아를 사용합니다. 알았어 .. –