Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #4976 from kreynolds/fix_eager_without_pkey

Fix eagerly loading associations without primary keys
  • Loading branch information...
commit e20a790b9e63ff7ff71753b24bd88c0a62dc2cf7 2 parents 1c1f654 + 07dad77
@jonleighton jonleighton 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
8 activerecord/test/cases/associations/join_dependency_test.rb
@@ -0,0 +1,8 @@
+require "cases/helper"
+require 'models/edge'
+
+class JoinDependencyTest < ActiveRecord::TestCase
+ def test_column_names_with_alias_handles_nil_primary_key
+ assert_equal Edge.column_names, ActiveRecord::Associations::JoinDependency::JoinBase.new(Edge).column_names_with_alias.map(&:first)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.