开发者

Rails migration refactoring

开发者 https://www.devze.com 2023-01-28 11:15 出处:网络
In migrations we can write in following way t.integer :escalated_by, escalated_to, query_id But I don\'t like this way.

In migrations we can write in following way

t.integer :escalated_by, escalated_to, query_id

But I don't like this way.

Rather I would like something like code below:

  def self.up
    create_table :query_escalations do |t|
      t.integer do
   开发者_运维技巧     :escalated_by
        :escalated_to
        :query_id
      end
      t.timestamps
    end
  end

I think this is more readable. Does rails supports this way? or is there any way similar to this?


NO. Rails does not suppor that style. And if you want that style then you will have to do a lot of work.

Migration is complex piece of code. I will suggest to stick with what rails provides.

For what it's work up and down will be instance methods in Rails 3.1 instead of being class methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消