W3cubDocs

/Ruby on Rails 6.0

module ActiveRecord::ModelSchema

Public Class Methods

implicit_order_column Show source
# File activerecord/lib/active_record/model_schema.rb, line 112
    

The name of the column records are ordered by if no explicit order clause is used during an ordered finder call. If not set the primary key is used.

implicit_order_column=(column_name) Show source
# File activerecord/lib/active_record/model_schema.rb, line 120
included do
  mattr_accessor :primary_key_prefix_type, instance_writer: false

  class_attribute :table_name_prefix, instance_writer: false, default: ""
  class_attribute :table_name_suffix, instance_writer: false, default: ""
  class_attribute :schema_migrations_table_name, instance_accessor: false, default: "schema_migrations"
  class_attribute :internal_metadata_table_name, instance_accessor: false, default: "ar_internal_metadata"
  class_attribute :pluralize_table_names, instance_writer: false, default: true
  class_attribute :implicit_order_column, instance_accessor: false

  self.protected_environments = ["production"]
  self.inheritance_column = "type"
  self.ignored_columns = [].freeze

  delegate :type_for_attribute, to: :class

  initialize_load_schema_monitor
end

Sets the column to sort records by when no explicit order clause is used during an ordered finder call. Useful when the primary key is not an auto-incrementing integer, for example when it's a UUID. Note that using a non-unique column can result in non-deterministic results.

internal_metadata_table_name Show source
# File activerecord/lib/active_record/model_schema.rb, line 83
    

The name of the internal metadata table. By default, the value is "ar_internal_metadata".

internal_metadata_table_name=(table_name) Show source
# File activerecord/lib/active_record/model_schema.rb, line 89
    

Sets the name of the internal metadata table.

pluralize_table_names Show source
# File activerecord/lib/active_record/model_schema.rb, line 97
    

Indicates whether table names should be the pluralized versions of the corresponding class names. If true, the default table name for a Product class will be “products”. If false, it would just be “product”. See table_name for the full rules on table/class naming. This is true, by default.

pluralize_table_names=(value) Show source
# File activerecord/lib/active_record/model_schema.rb, line 105
    

Set whether table names should be the pluralized versions of the corresponding class names. If true, the default table name for a Product class will be “products”. If false, it would just be “product”. See table_name for the full rules on table/class naming. This is true, by default.

primary_key_prefix_type Show source
# File activerecord/lib/active_record/model_schema.rb, line 19
    

The prefix type that will be prepended to every primary key column name. The options are :table_name and :table_name_with_underscore. If the first is specified, the Product class will look for “productid” instead of “id” as the primary column. If the latter is specified, the Product class will look for “product_id” instead of “id”. Remember that this is a global setting for all Active Records.

primary_key_prefix_type=(prefix_type) Show source
# File activerecord/lib/active_record/model_schema.rb, line 29
    

Sets the prefix type that will be prepended to every primary key column name. The options are :table_name and :table_name_with_underscore. If the first is specified, the Product class will look for “productid” instead of “id” as the primary column. If the latter is specified, the Product class will look for “product_id” instead of “id”. Remember that this is a global setting for all Active Records.

schema_migrations_table_name Show source
# File activerecord/lib/active_record/model_schema.rb, line 71
    

The name of the schema migrations table. By default, the value is "schema_migrations".

schema_migrations_table_name=(table_name) Show source
# File activerecord/lib/active_record/model_schema.rb, line 77
    

Sets the name of the schema migrations table.

table_name_prefix Show source
# File activerecord/lib/active_record/model_schema.rb, line 35
    

The prefix string to prepend to every table name.

table_name_prefix=(prefix) Show source
# File activerecord/lib/active_record/model_schema.rb, line 48
    

Sets the prefix string to prepend to every table name. So if set to “basecamp_”, all table names will be named like “basecamp_projects”, “basecamp_people”, etc. This is a convenient way of creating a namespace for tables in a shared database. By default, the prefix is the empty string.

If you are organising your models within modules you can add a prefix to the models within a namespace by defining a singleton method in the parent module called ::table_name_prefix which returns your chosen prefix.

table_name_suffix Show source
# File activerecord/lib/active_record/model_schema.rb, line 54
    

The suffix string to append to every table name.

table_name_suffix=(suffix) Show source
# File activerecord/lib/active_record/model_schema.rb, line 65
    

Works like table_name_prefix=, but appends instead of prepends (set to “_basecamp” gives “projects_basecamp”, “people_basecamp”). By default, the suffix is the empty string.

If you are organising your models within modules, you can add a suffix to the models within a namespace by defining a singleton method in the parent module called ::table_name_suffix which returns your chosen suffix.

© 2004–2019 David Heinemeier Hansson
Licensed under the MIT License.