aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-09-07 02:11:21 -0700
committerJon Leighton <j@jonathanleighton.com>2012-09-07 02:11:21 -0700
commite20a790b9e63ff7ff71753b24bd88c0a62dc2cf7 (patch)
treed1e0b3d17d1c34baeb92a0f68ae43909e8675a9c /activerecord
parent1c1f65430046fa0041acc898d8d6f5377f20806e (diff)
parent07dad778d18b45eb6d6a003d3ba7cb8528e9c720 (diff)
downloadrails-e20a790b9e63ff7ff71753b24bd88c0a62dc2cf7.tar.gz
rails-e20a790b9e63ff7ff71753b24bd88c0a62dc2cf7.tar.bz2
rails-e20a790b9e63ff7ff71753b24bd88c0a62dc2cf7.zip
Merge pull request #4976 from kreynolds/fix_eager_without_pkey
Fix eagerly loading associations without primary keys
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_part.rb2
-rw-r--r--activerecord/test/cases/associations/join_dependency_test.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_part.rb b/activerecord/lib/active_record/associations/join_dependency/join_part.rb
index 2b1d888a9a..711f7b3ce1 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_part.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_part.rb
@@ -54,7 +54,7 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/associations/join_dependency_test.rb b/activerecord/test/cases/associations/join_dependency_test.rb
new file mode 100644
index 0000000000..08c166dc33
--- /dev/null
+++ b/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 \ No newline at end of file