美文网首页
获得ActiveRecord object对象的属性类型

获得ActiveRecord object对象的属性类型

作者: wylszz | 来源:发表于2016-12-19 10:42 被阅读0次

获得单个属性类型的方法:

(1)User.columns_hash["name"].type
(2)User.type_for_attribute('name').type

如果想获得model的所有属性类型列表,可以如下:

(1)User.columns_hash.map {|k,v| v.type} 
(2)User.columns.map(&:type) #gets them all
(3)User.columns.map(&:type).uniq #gets the unique ones

相关文章

网友评论

      本文标题:获得ActiveRecord object对象的属性类型

      本文链接:https://www.haomeiwen.com/subject/iixtvttx.html