module ActiveRecord::ModelSchema::ClassMethods
def table_name
self.table_name = "mice"
class Mouse < ActiveRecord::Base
You can also set your own table name explicitly:
# => "posts"
PostRecord.table_name
end
end
end
ActiveModel::Name.new(self, nil, "Post")
def model_name
class << self
class PostRecord < ActiveRecord::Base
used for the table name as well:
table name. In case a custom Active Model Name is defined, it will be
Active Model Naming's +model_name+ is the base name used to guess the
Invoice::Lineitem becomes "myapp_invoice_lineitems".
the table name guess for an Invoice class becomes "myapp_invoices".
+table_name_suffix+ is appended. So if you have "myapp_" as a prefix,
Additionally, the class-level +table_name_prefix+ is prepended and the
invoice/lineitem.rb Invoice::Lineitem lineitems
file class table_name
end
end
class Lineitem < ActiveRecord::Base
module Invoice
invoice.rb Invoice::Lineitem invoice_lineitems
file class table_name
end
end
class Lineitem < ActiveRecord::Base
class Invoice < ActiveRecord::Base
invoice.rb Invoice invoices
file class table_name
end
class Invoice < ActiveRecord::Base
==== Examples
the parent's table name. Enclosing modules are not considered.
Nested classes are given table names prefixed by the singular form of
English inflections. You can add new inflections in config/initializers/inflections.rb.
are handled by the Inflector class in Active Support, which knows almost all common
to guess the table name even when called on Reply. The rules used to do the guess
looks like: Reply < Message < ActiveRecord::Base, then Message is used
inheritance hierarchy descending directly from ActiveRecord::Base. So if the hierarchy
Guesses the table name (in forced lower-case) based on the name of the class in the
def table_name reset_table_name unless defined?(@table_name) @table_name end