Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1162 from guilleiguaran/singularize_individual_ta…

…ble_name

Singularize individual table name
  • Loading branch information...
commit d62a39a22b7ad56efa79089177aa06fda0d41f86 2 parents 7288682 + e0e8918
Jon Leighton jonleighton authored
4 activerecord/lib/active_record/associations/alias_tracker.rb
View
@@ -49,8 +49,8 @@ def aliased_name_for(table_name, aliased_name = nil)
end
end
- def pluralize(table_name)
- ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name.to_s
+ def pluralize(table_name, base)
+ base.pluralize_table_names ? table_name.to_s.pluralize : table_name.to_s
end
private
2  activerecord/lib/active_record/associations/join_helper.rb
View
@@ -32,7 +32,7 @@ def table_name_for(reflection)
end
def table_alias_for(reflection, join = false)
- name = alias_tracker.pluralize(reflection.name)
+ name = alias_tracker.pluralize(reflection.name, reflection.active_record)
name << "_#{alias_suffix}"
name << "_join" if join
name
4 activerecord/lib/active_record/base.rb
View
@@ -393,8 +393,8 @@ class Base
# 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.
- cattr_accessor :pluralize_table_names, :instance_writer => false
- @@pluralize_table_names = true
+ class_attribute :pluralize_table_names, :instance_writer => false
+ self.pluralize_table_names = true
##
# :singleton-method:
5 activerecord/test/cases/associations/join_model_test.rb
View
@@ -708,12 +708,9 @@ def test_has_many_through_goes_through_all_sti_classes
end
def test_has_many_with_pluralize_table_names_false
- engine = Engine.create(:car_id => 1)
- Aircraft.pluralize_table_names = false
+ engine = Engine.create!(:car_id => 1)
aircraft = Aircraft.create!(:name => "Airbus 380", :id => 1)
assert_equal aircraft.engines, [engine]
- ensure
- ActiveRecord::Base.pluralize_table_names = true
end
private
9 activerecord/test/cases/base_test.rb
View
@@ -367,6 +367,15 @@ def test_table_name_guesses_with_inherited_prefixes_and_suffixes
GUESSED_CLASSES.each(&:reset_table_name)
end
+ def test_singular_table_name_guesses_for_individual_table
+ CreditCard.pluralize_table_names = false
+ CreditCard.reset_table_name
+ assert_equal "credit_card", CreditCard.table_name
+ assert_equal "categories", Category.table_name
+ ensure
+ CreditCard.pluralize_table_names = true
+ CreditCard.reset_table_name
+ end
if current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter)
def test_update_all_with_order_and_limit
1  activerecord/test/models/aircraft.rb
View
@@ -1,3 +1,4 @@
class Aircraft < ActiveRecord::Base
+ self.pluralize_table_names = false
has_many :engines, :foreign_key => "car_id"
end
Please sign in to comment.
Something went wrong with that request. Please try again.