Changeset 4770
- Timestamp:
- 08/16/06 09:46:43 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/base.rb (modified) (2 diffs)
- trunk/activerecord/test/base_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r4767 r4770 1 1 *SVN* 2 3 * Nested classes are given table names prefixed by the singular form of the parent's table name. [Jeremy Kemper] 4 Example: Invoice::Lineitem is given table name invoice_lineitems 2 5 3 6 * Migrations: uniquely name multicolumn indexes so you don't have to. [Jeremy Kemper] trunk/activerecord/lib/active_record/base.rb
r4743 r4770 589 589 # in Active Support, which knows almost all common English inflections (report a bug if your inflection isn't covered). 590 590 # 591 # Additionally, the class-level table_name_prefix is prepended to the table_name and the table_name_suffix is appended. 592 # So if you have "myapp_" as a prefix, the table name guess for an Account class becomes "myapp_accounts". 593 # 594 # You can also overwrite this class method to allow for unguessable links, such as a Mouse class with a link to a 595 # "mice" table. Example: 591 # Nested classes are given table names prefixed by the singular form of 592 # the parent's table name. Example: 593 # file class table_name 594 # invoice.rb Invoice invoices 595 # invoice/lineitem.rb Invoice::Lineitem invoice_lineitems 596 # 597 # Additionally, the class-level table_name_prefix is prepended and the 598 # table_name_suffix is appended. So if you have "myapp_" as a prefix, 599 # the table name guess for an Invoice class becomes "myapp_invoices". 600 # Invoice::Lineitem becomes "myapp_invoice_lineitems". 601 # 602 # You can also overwrite this class method to allow for unguessable 603 # links, such as a Mouse class with a link to a "mice" table. Example: 596 604 # 597 605 # class Mouse < ActiveRecord::Base 598 # set_table_name "mice"606 # set_table_name "mice" 599 607 # end 600 608 def table_name … … 603 611 604 612 def reset_table_name #:nodoc: 605 name = "#{table_name_prefix}#{undecorated_table_name(base_class.name)}#{table_name_suffix}" 613 # If this is a nested class, prefix with singular parent table name. 614 if parent < ActiveRecord::Base && !parent.abstract_class? 615 contained = parent.table_name 616 contained = contained.singularize if parent.pluralize_table_names 617 contained << '_' 618 end 619 name = "#{table_name_prefix}#{contained}#{undecorated_table_name(base_class.name)}#{table_name_suffix}" 606 620 set_table_name(name) 607 621 name trunk/activerecord/test/base_test.rb
r4670 r4770 14 14 class Category < ActiveRecord::Base; end 15 15 class Smarts < ActiveRecord::Base; end 16 class CreditCard < ActiveRecord::Base; end 16 class CreditCard < ActiveRecord::Base 17 class PinNumber < ActiveRecord::Base; end 18 end 17 19 class MasterCreditCard < ActiveRecord::Base; end 18 20 class Post < ActiveRecord::Base; end … … 373 375 assert_equal "smarts", Smarts.table_name 374 376 assert_equal "credit_cards", CreditCard.table_name 377 assert_equal "credit_card_pin_numbers", CreditCard::PinNumber.table_name 375 378 assert_equal "master_credit_cards", MasterCreditCard.table_name 376 379 377 380 ActiveRecord::Base.pluralize_table_names = false 378 [Category, Smarts, CreditCard, MasterCreditCard].each{|c| c.reset_table_name}381 [Category, Smarts, CreditCard, CreditCard::PinNumber, MasterCreditCard].each{|c| c.reset_table_name} 379 382 assert_equal "category", Category.table_name 380 383 assert_equal "smarts", Smarts.table_name 381 384 assert_equal "credit_card", CreditCard.table_name 385 assert_equal "credit_card_pin_number", CreditCard::PinNumber.table_name 382 386 assert_equal "master_credit_card", MasterCreditCard.table_name 383 387 ActiveRecord::Base.pluralize_table_names = true 384 [Category, Smarts, CreditCard, MasterCreditCard].each{|c| c.reset_table_name}388 [Category, Smarts, CreditCard, CreditCard::PinNumber, MasterCreditCard].each{|c| c.reset_table_name} 385 389 386 390 ActiveRecord::Base.table_name_prefix = "test_" … … 411 415 assert_equal "category", Category.table_name 412 416 ActiveRecord::Base.pluralize_table_names = true 413 [Category, Smarts, CreditCard, MasterCreditCard].each{|c| c.reset_table_name}417 [Category, Smarts, CreditCard, CreditCard::PinNumber, MasterCreditCard].each{|c| c.reset_table_name} 414 418 end 415 419