代码之家  ›  专栏  ›  技术社区  ›  Brian Sullivan

是否可以在Rails ActiveRecord迁移中指定SQL Server架构名称?

  •  3
  • Brian Sullivan  · 技术社区  · 15 年前

    我工作的当前约定是使用SQL Server模式,如名称空间(如company.employees、company.branches等),是否可以使用ActiveRecord迁移来使用SQL Server中的默认“dbo”模式以外的其他模式?

    1 回复  |  直到 14 年前
        1
  •  7
  •   Harish Shetty    15 年前

    在迁移中,提供带有模式前缀的表名以创建表和删除表调用。

    create_table("Company.Employees") do |t|
      t.column :name, :string, :limit => 60
      # Other fields here
    end
    

    在模型中,使用 set_table_name .

    class Employees < ActiveRecord::Base
      set_table_name "Company.Employees"
    end
    

    另一方面

    如果Rails应用程序中使用的所有表都属于同一个模式,那么可以将该模式指定为database.yml文件中指定的db用户的默认模式。