What are the brackets [5.1] after ActiveRecord Migration and how does it work? [duplicate]

寵の児 提交于 2019-11-26 08:38:24

问题


This question already has an answer here:

  • What’s does the [5.0] in Rails 5’s ActiveRecord::Migration mean? 2 answers

When generating a new migration using bin/rails g migration CreateUser the first line will look like this:

class CreateUser < ActiveRecord::Migration[5.1]

What does the [5.1] stand for and how does it work?

This is a follow up on What’s does the [5.0] in Rails 5’s ActiveRecord::Migration mean? as it does not explain how this is legal ruby and does not show up in search using [5.1] or brackets


回答1:


This is the new migration versioning introduced with Rails 5. The number indicates the migration version the migration was created with, in this case version 5.1 and should be used with Rails versions >= 5.0.

This is a class function def self.[](version) of the ActiveRecord::Migration, which calls Compatibility.find(version) and is used for backward compatibility.

Here are the code references from GitHub:

  • ActiveRecord::Migration::[]
  • ActiveRecord::Migration::Compatibility


来源:https://stackoverflow.com/questions/47126483/what-are-the-brackets-5-1-after-activerecord-migration-and-how-does-it-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!