diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-08-15 16:00:35 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-08-15 16:01:01 +0100 |
commit | 57423d815b3747aa382cd3859a15bffa538525ad (patch) | |
tree | 4ab80289139009b5476db1b62253fb034af56205 /activerecord/lib | |
parent | 4c743d9fceabc254a6e5e92412753b31fb0a24ff (diff) | |
download | rails-57423d815b3747aa382cd3859a15bffa538525ad.tar.gz rails-57423d815b3747aa382cd3859a15bffa538525ad.tar.bz2 rails-57423d815b3747aa382cd3859a15bffa538525ad.zip |
Ensure empty has_many :through association preloaded via joins is marked as loaded. Fixes #2054.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 504f25271c..6c878f0f00 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -188,13 +188,12 @@ module ActiveRecord association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil? set_target_and_inverse(join_part, association, record) else - return if row[join_part.aliased_primary_key].nil? - association = join_part.instantiate(row) + association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil? case macro when :has_many, :has_and_belongs_to_many other = record.association(join_part.reflection.name) other.loaded! - other.target.push(association) + other.target.push(association) if association other.set_inverse_instance(association) when :belongs_to set_target_and_inverse(join_part, association, record) |