开发者

Rails migration refactoring

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜