我使用ruby和activerecord来获取关于mysql表的信息。
我希望我可以直接从我的模型类中获得这些信息,这可能吗?
假设我有我的模型:
class Product < ActiveRecord::Base
end现在是否可以获取有关以下内容的信息:
1. mysql table
2. columns
3. column types或者我必须更深入地研究ActiveRecord模块才能得到它?
发布于 2012-04-22 06:00:58
Product.table_nameProduct.column_namesProduct.columns_hash['title'].type发布于 2012-04-22 05:47:39
看一看ActiveRecord::ModelSchema::ClassMethods
class Product < ActiveRecord::Base
self.table_name # 1
self.columns # 2
self.columns_hash['name'].type # 3
endhttps://stackoverflow.com/questions/10263214
复制相似问题