aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSergio Cambra <sergio@programatica.es>2014-11-21 15:54:01 -1000
committerSergio Cambra <sergio@programatica.es>2015-01-07 01:23:19 -1000
commit33a5416461bc5068d85d33259310f56625569e86 (patch)
tree8794404dbb36af4793c3214d2f6f029fbc1d5043 /activerecord/lib
parentf9e0ec544989c2d93ed40d0acdbc627f6a624eb1 (diff)
downloadrails-33a5416461bc5068d85d33259310f56625569e86.tar.gz
rails-33a5416461bc5068d85d33259310f56625569e86.tar.bz2
rails-33a5416461bc5068d85d33259310f56625569e86.zip
Includes HABTM returns correct size now. It's caused by the join dependency
only instantiates one HABTM object because the join table hasn't a primary key. Updated commit from @bigxiang commit dbaa837 Fixes #16032. Examples: before: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 1 after: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 3
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index 4b75370171..85febcc771 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -150,7 +150,8 @@ module ActiveRecord
message_bus.instrument('instantiation.active_record', payload) do
result_set.each { |row_hash|
- parent = parents[row_hash[primary_key]] ||= join_root.instantiate(row_hash, column_aliases)
+ parent_key = primary_key ? row_hash[primary_key] : row_hash
+ parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases)
construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
}
end
@@ -232,7 +233,7 @@ module ActiveRecord
end
def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
- primary_id = ar_parent.id
+ primary_id = ar_parent.id || row
parent.children.each do |node|
if node.reflection.collection?