Ruby on Rails Custom Migration Generator

后端 未结 3 1109
走了就别回头了
走了就别回头了 2021-02-06 11:38

I\'m creating a Rails gem that integrates closely with Active Record. The gem requires a number of fields to be defined. For example:

class User < ActiveRecor         


        
3条回答
  •  我在风中等你
    2021-02-06 12:16

    I consider t.attached similar to t.references in a polymorphic association.

    With reference to the references method you can have something like below

    def attached(*args)
      options = args.extract_options!
      column(:avatar_identifier, :string, options)
      column(:avatar_extension, :string, options)
      column(:avatar_size, :integer, options)
    end
    

    You might like to extend ActiveRecord::ConnectionAdapters::TableDefinition
    Have look at this http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-references

提交回复
热议问题