diff options
author | Sergio Cambra <sergio@programatica.es> | 2014-11-21 15:54:01 -1000 |
---|---|---|
committer | Sergio Cambra <sergio@programatica.es> | 2015-01-07 01:23:19 -1000 |
commit | 33a5416461bc5068d85d33259310f56625569e86 (patch) | |
tree | 8794404dbb36af4793c3214d2f6f029fbc1d5043 /activerecord/lib | |
parent | f9e0ec544989c2d93ed40d0acdbc627f6a624eb1 (diff) | |
download | rails-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.rb | 5 |
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? |