Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the table, column and type information from a model?

I'm using ruby and activerecord to get information about a mysql table.

I was hoping I could get this information directly from my model class, is this possible?

Say I have my model:

class Product < ActiveRecord::Base
end

Is it now possible for me to get information regarding:

1. mysql table
2. columns
3. column types

Or do I have to look somewhere deeper into the ActiveRecord module to get this?

like image 443
Blankman Avatar asked Apr 21 '12 21:04

Blankman


1 Answers

  1. Product.table_name
  2. Product.column_names
  3. Product.columns_hash['title'].type
like image 69
jdoe Avatar answered Oct 11 '22 10:10

jdoe