[英]Can I get the table, column and type information from a model?
我正在使用ruby和activerecord来获取有关mysql表的信息。
我希望我可以直接从我的模型类中获取这些信息,这可能吗?
说我有我的模特:
class Product < ActiveRecord::Base
end
我现在可以获得以下信息:
1. mysql table
2. columns
3. column types
或者我是否必须深入了解ActiveRecord模块才能获得此功能?
Product.table_name
Product.column_names
Product.columns_hash['title'].type
看看ActiveRecord :: ModelSchema :: ClassMethods :
class Product < ActiveRecord::Base
self.table_name # 1
self.columns # 2
self.columns_hash['name'].type # 3
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.