당신이 볼 수있는 방법을 살펴보십시오 :
> Post.columns.last
=> #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x007feee6bc2320
@array=false,
@cast_type=
#<ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer:0x007feee6bd36c0
@limit=nil,
@precision=nil,
@range=-2147483648...2147483648,
@scale=nil>,
@default="1",
@default_function=nil,
@name="max_likes",
@null=false,
@sql_type="integer">
는의가 있다고 가정 해 봅시다 12 게시물입니다.
> Post.count
=> 12
columns
에있는 모든 값
액세스 할 수 있습니다, 그 결과를 제한 할 수 있습니다.
> Post.columns.select { |c| c.name == 'max_likes' }.each do |c|
puts c.sql_type
end
=> integer
: 당신이 필터링하면
> Post.columns.count { |c| c.name == 'max_likes' }
=> 1
> Post.columns.count { |c| c.sql_type == 'integer' }
=> 5
> Post.columns.count { |c| c.precision == nil }
=> 12
> Post.columns.count { |c| c.default == "1" }
=> 2
, 당신은 당신이 선택한 열이 필요 무엇이든 할 수 있습니다