簡體   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