123456789_123456789_123456789_123456789_123456789_

Module: ActiveRecord::ModelSchema

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Defined in: activerecord/lib/active_record/model_schema.rb

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

Instance Method Summary

  • #id_value

    Returns the underlying column value for a column named “id”.

DSL Calls

included

[ GitHub ]


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'activerecord/lib/active_record/model_schema.rb', line 157

included do
  class_attribute :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 :, 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
  class_attribute :immutable_strings_by_default, instance_accessor: false

  class_attribute :inheritance_column, instance_accessor: false, default: "type"
  singleton_class.class_eval do
    alias_method :_inheritance_column=, :inheritance_column=
    private :_inheritance_column=
    alias_method :inheritance_column=, :real_inheritance_column=
  end

  self.protected_environments = ["production"]

  self.ignored_columns = [].freeze

  delegate :type_for_attribute, :column_for_attribute, to: :class

  initialize_load_schema_monitor
end

Class Method Details

.immutable_strings_by_default=(bool)

Determines whether columns should infer their type as :string or :immutable_string. This setting does not affect the behavior of attribute :foo, :string. Defaults to false.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 128

RDoc directive :singleton-method: immutable_strings_by_default=

.implicit_order_column

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.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 112

RDoc directive :singleton-method: implicit_order_column

.implicit_order_column=(column_name)

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. Records are subsorted by the primary key if it exists to ensure deterministic results.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 119

RDoc directive :singleton-method: implicit_order_column=

.inheritance_column

The name of the table column which stores the class name on single-table inheritance situations.

The default inheritance column name is type, which means it’s a reserved word inside Active Record. To be able to use single-table inheritance with another column name, or to use the column type in your own model for something else, you can set inheritance_column:

self.inheritance_column = 'zoink'
[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 136

RDoc directive :singleton-method: inheritance_column

.inheritance_column=(column)

Defines the name of the table column which will store the class name on single-table inheritance situations.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 157

RDoc directive :singleton-method: inheritance_column=

.internal_metadata_table_name

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

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 84

RDoc directive :singleton-method: 

.internal_metadata_table_name=(table_name)

Sets the name of the internal metadata table.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 90

RDoc directive :singleton-method: =

.pluralize_table_names

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.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 96

RDoc directive :singleton-method: pluralize_table_names

.pluralize_table_names=(value)

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.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 104

RDoc directive :singleton-method: pluralize_table_names=

.primary_key_prefix_type

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.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 16

RDoc directive :singleton-method: primary_key_prefix_type

.primary_key_prefix_type=(prefix_type)

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.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 26

RDoc directive :singleton-method: primary_key_prefix_type=

.schema_migrations_table_name

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

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 72

RDoc directive :singleton-method: schema_migrations_table_name

.schema_migrations_table_name=(table_name)

Sets the name of the schema migrations table.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 78

RDoc directive :singleton-method: schema_migrations_table_name=

.table_name_prefix

The prefix string to prepend to every table name.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 36

RDoc directive :singleton-method: table_name_prefix

.table_name_prefix=(prefix)

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.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 42

RDoc directive :singleton-method: table_name_prefix=

.table_name_suffix

The suffix string to append to every table name.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 55

RDoc directive :singleton-method: table_name_suffix

.table_name_suffix=(suffix)

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.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 61

RDoc directive :singleton-method: table_name_suffix=

Instance Method Details

#id_value

Returns the underlying column value for a column named “id”. Useful when defining a composite primary key including an “id” column so that the value is readable.

[ GitHub ]

  
# File 'activerecord/lib/active_record/model_schema.rb', line 10

rdoc_method :method: id_value