Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collection_singular_ids= bug #27865

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Fix `association_primary_key_type` for reflections with symbol primary key

Fixes #27864

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind to add your name here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry about that!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

*Daniel Colson*

* Virtual/generated column support for MySQL 5.7.5+ and MariaDB 5.2.0+.

MySQL generated columns: https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,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
Expand Down Expand Up @@ -835,7 +835,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.
Expand Down
9 changes: 9 additions & 0 deletions activerecord/test/cases/reflection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,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 }
Expand Down