columns- Returns an array of
Columnobjects. columns_hash- Similar to the
columnsmethod but returns aHashusing column names as keys andColumnobjects as values. column_names- Returns a simple array of column names for the model.
The Column objects returned by columns and columns_hash can then be used to get information such as the data type and default values, for example:
User.columns_hash['email'].type
=> :string
User.columns_hash['email'].default
=> nil
User.columns_hash['email'].sql_type
=> "varchar(255)"


2 comments
Comment on Accessing column information with ActiveRecord by lg2046 li
April 27th, 2009 @ 07:51 – permalink
Comment on Accessing column information with ActiveRecord by oliver bruening
November 25th, 2010 @ 15:06 – permalink
Leave a reply
You can use Markdown in your comment as well as plain HTML. You can use
<filter:jscode lang="ruby">and</filter:jscode>tags to surround code blocks (supported languages are css, html, javascript and ruby). Your email address will not be published.If your comment doesn’t appear immediately after posting it could have been marked as spam. Don’t worry: we regularly check for and approve incorrectly filtered comments so you shouldn’t have to wait too long for it to be shown.