Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14793 from arthurnn/fixes_8928

Fixed has_many association to make it support irregular inflections.
  • Loading branch information...
commit 88d8f6e5eb14c277aecd3d47727dda68fc925f25 1 parent b8a91a6
@rafaelfranca rafaelfranca authored
View
6 activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Fixed has_many association to make it support irregular inflections.
+
+ Fixes #8928.
+
+ *arthurnn*, *Javier Goizueta*
+
* Fixed a problem where count used with a grouping was not returning a Hash.
Fixes #14721.
View
4 activerecord/lib/active_record/reflection.rb
@@ -368,9 +368,9 @@ def polymorphic?
private
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
View
8 activerecord/test/cases/reflection_test.rb
@@ -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 88d8f6e

Please sign in to comment.
Something went wrong with that request. Please try again.