简体   繁体   中英

How can I get the datatype of an attribute from a Rails model?

I am using Postgres in a Rails project and I have discovered that I need to change all of my varchar datatypes to citext . Rather than do this by hand, I want to just create a migration that loops through all of the models and their attributes and converts them as necessary.

Most of these models are empty, so it's not a matter of instantiating them. I need to find out if ActiveRecord "knows" what the datatype of its corresponding database column is.

@model.column_for_attribute('title').type

那可能就是你要找的东西。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM