Skip to content

Commit

Permalink
Fix eagerly loading associations without primary keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelley Reynolds committed Feb 9, 2012
1 parent b02c87e commit 6050d01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions activerecord/test/cases/associations/eager_test.rb
Expand Up @@ -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 }
Expand Down

1 comment on commit 6050d01

@jeremyf
Copy link

@jeremyf jeremyf commented on 6050d01 May 3, 2012

Choose a reason for hiding this comment

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

@tenderlove @jonleighton the tests all pass

Please sign in to comment.