Permalink
Browse files

Merge pull request #27865 from composerinteralia/collection-ids-sette…

…r-bug

Fix collection_singular_ids= bug
  • Loading branch information...
eileencodes committed Feb 3, 2017
1 parent 11b6aa0 commit 93a44497ed7b28f5691a5cb1685261af5dcf64c1
@@ -1,3 +1,9 @@
+* Fix `association_primary_key_type` for reflections with symbol primary key
+
+ Fixes #27864
+
+ *Daniel Colson*
+
* Place generated migrations into the path set by `config.paths["db/migrate"]`
*Kevin Glowacz*
@@ -399,7 +399,7 @@ def association_primary_key(klass = nil)
end
def association_primary_key_type
- klass.type_for_attribute(association_primary_key)
+ klass.type_for_attribute(association_primary_key.to_s)
end
def active_record_primary_key
@@ -856,7 +856,7 @@ def association_primary_key(klass = nil)
end
def association_primary_key_type
- klass.type_for_attribute(association_primary_key)
+ klass.type_for_attribute(association_primary_key.to_s)
end
# Gets an array of possible <tt>:through</tt> source reflection names in both singular and plural form.
@@ -325,6 +325,15 @@ def test_association_primary_key
assert_equal "custom_primary_key", Author.reflect_on_association(:tags_with_primary_key).association_primary_key.to_s # nested
end
+ def test_association_primary_key_type
+ # Normal Association
+ assert_equal :integer, Author.reflect_on_association(:posts).association_primary_key_type.type
+ assert_equal :string, Author.reflect_on_association(:essay).association_primary_key_type.type
+
+ # Through Association
+ assert_equal :string, Author.reflect_on_association(:essay_category).association_primary_key_type.type
+ end
+
def test_association_primary_key_raises_when_missing_primary_key
reflection = ActiveRecord::Reflection.create(:has_many, :edge, nil, {}, Author)
assert_raises(ActiveRecord::UnknownPrimaryKey) { reflection.association_primary_key }

0 comments on commit 93a4449

Please sign in to comment.