繁体   English   中英

我可以从模型中获取表格,列和类型信息吗?

[英]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模块才能获得此功能?

  1. Product.table_name
  2. Product.column_names
  3. 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.

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