Permalink
Browse files

Merge pull request #4976 from kreynolds/fix_eager_without_pkey

Fix eagerly loading associations without primary keys
  • Loading branch information...
2 parents 1c1f654 + 07dad77 commit e20a790b9e63ff7ff71753b24bd88c0a62dc2cf7 @jonleighton jonleighton committed Sep 7, 2012
@@ -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
@@ -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

0 comments on commit e20a790

Please sign in to comment.