Skip to content
  • Volmer Campos Soares's avatar
    d8b17685
    Compute table name based on model name · d8b17685
    Volmer Campos Soares authored
    Instead of using the Active Record Base's class name, the table name is
    now inferred based on its model name object. This allows customization
    of the table name pattern since a distinct instance of
    `ActiveModel::Name` can be used instead.
    
    For example, to map a `PostRecord` class to a `posts` table:
    
    ```ruby
    
     class PostRecord < ActiveRecord::Base
       class << self
         def model_name
           ActiveModel::Name.new(self, nil, 'Post')
         end
       end
     end
    
     PostRecord.table_name
     # => "posts"
    ```
    d8b17685
    Compute table name based on model name
    Volmer Campos Soares authored
    Instead of using the Active Record Base's class name, the table name is
    now inferred based on its model name object. This allows customization
    of the table name pattern since a distinct instance of
    `ActiveModel::Name` can be used instead.
    
    For example, to map a `PostRecord` class to a `posts` table:
    
    ```ruby
    
     class PostRecord < ActiveRecord::Base
       class << self
         def model_name
           ActiveModel::Name.new(self, nil, 'Post')
         end
       end
     end
    
     PostRecord.table_name
     # => "posts"
    ```
Loading