大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 任何Rails插件,用于添加有关ActiveRecord迁移文件中每列的注释?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
As far as I know,I can add COMMENT to each table and column.
我记不起一个允许我写的插件名称如下:
t.String :name,:comment => "A user's fullname" t.String :label,:comment => "name of color" t.text :value,:comment => "self intro" t.Integer :position,:comment => "1 is left,2 is right"
神奇的语句被翻译成SQL,就像
create table test ( name varchar(255) not null COMMENT 'blahblah',label varchar(255) null COMMENT 'hahaha' text varchar(255) not null,position int(11) );
有人知道插件的名字吗?
>我不是在寻找Dave Thomas的Annotate Models plugins.我的意思是评论是在MySQL查询中.
正如您所看到的,Struct定义了各种列选项(例如:limit和:default.)您可以使用:comment扩展该结构,然后修改#to_sql以生成所需的SQl.您还需要修改TableDefinition#列以设置:comment属性.
以下内容已经过测试并且有效(适用于MySQL):
@H_212_6@module ActiveRecord module ConnectionAdapters class columnDefinition attr_accessor :comment def to_sql_with_comment column_sql = to_sql_without_comment return column_sql if comment.nil? "#{column_sql} COMMENT '#{Base.quote_String(comment)}'" end alias_method_chain :to_sql,:comment end class TableDefinition # Completely replaces (and duplicates the exisTing code,but there's # no place to really hook into the middle of this.) def column(name,type,options = {}) column = self[name] || columnDefinition.new(@base,name,typE) if options[:limit] column.limit = options[:limit] elsif native[type.to_sym].is_a?(Hash) column.limit = native[type.to_sym][:limit] end column.precision = options[:precision] column.scale = options[:scale] column.default = options[:default] column.null = options[:null] column.comment = options[:comment] @columns << column unless @columns.include? column self end end end end以上是大佬教程为你收集整理的ruby-on-rails – 任何Rails插件,用于添加有关ActiveRecord迁移文件中每列的注释?全部内容,希望文章能够帮你解决ruby-on-rails – 任何Rails插件,用于添加有关ActiveRecord迁移文件中每列的注释?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。