Permalink
Browse files

Merge pull request #14793 from arthurnn/fixes_8928

Fixed has_many association to make it support irregular inflections.
Conflicts:
	activerecord/CHANGELOG.md
  • Loading branch information...
1 parent 2a72514 commit 87a2f02199d21a2aaa978efee8f9838cf96b25a2 @rafaelfranca rafaelfranca committed Apr 18, 2014
@@ -1,3 +1,9 @@
+* Fixed has_many association to make it support irregular inflections.
+
+ Fixes #8928.
+
+ *arthurnn*, *Javier Goizueta*
+
* Calling `delete_all` on an unloaded `CollectionProxy` no longer
generates a SQL statement containing each id of the collection:
@@ -449,9 +449,9 @@ def can_find_inverse_of_automatically?(reflection)
end
def derive_class_name
- class_name = name.to_s.camelize
+ class_name = name.to_s
class_name = class_name.singularize if collection?
- class_name
+ class_name.camelize
end
def derive_foreign_key
@@ -87,6 +87,14 @@ def test_reflection_klass_for_nested_class_name
end
end
+ def test_irregular_reflection_class_name
+ ActiveSupport::Inflector.inflections do |inflect|
+ inflect.irregular 'plural_irregular', 'plurales_irregulares'
+ end
+ reflection = AssociationReflection.new(:has_many, 'plurales_irregulares', nil, {}, ActiveRecord::Base)
+ assert_equal 'PluralIrregular', reflection.class_name
+ end
+
def test_aggregation_reflection
reflection_for_address = AggregateReflection.new(
:composed_of, :address, nil, { :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ] }, Customer

0 comments on commit 87a2f02

Please sign in to comment.