Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix eagerly loading associations without primary keys

  • Loading branch information...
commit 6050d0177c3b9dc11c3e3c3dfa17530e27d90996 1 parent b02c87e
@kreynolds kreynolds authored
View
2  activerecord/lib/active_record/associations/join_dependency/join_part.rb
@@ -54,7 +54,7 @@ def column_names_with_alias
unless @column_names_with_alias
@column_names_with_alias = []
- ([primary_key] + (column_names - [primary_key])).each_with_index do |column_name, i|
+ ([primary_key] + (column_names - [primary_key])).compact.each_with_index do |column_name, i|
@column_names_with_alias << [column_name, "#{aliased_prefix}_r#{i}"]
end
end
View
13 activerecord/test/cases/associations/eager_test.rb
@@ -39,6 +39,19 @@ def test_eager_with_has_one_through_join_model_with_conditions_on_the_through
assert_nil member.favourite_club
end
+ def test_loading_with_one_association_without_primary_key
+ Comment.primary_key = nil
+ begin
+ assert_nothing_raised do
+ Post.includes(:comments).references(:comments).all
+ end
+ rescue
+ raise $!
+ ensure
+ Comment.primary_key = 'id'
+ end
+ end
+
def test_loading_with_one_association
posts = Post.find(:all, :include => :comments)
post = posts.find { |p| p.id == 1 }
Please sign in to comment.
Something went wrong with that request. Please try again.