diff options
author | Murray Steele <muz@h-lame.com> | 2009-03-12 13:49:16 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-03-12 13:49:16 +0000 |
commit | db26ace030f6704da6fc80bcc6cd00a2aee664ce (patch) | |
tree | e9f4a8c95527408fe936943e24d9a5bc36405bdb /activerecord/lib | |
parent | 92dadf6d7927fde1482ba1d96d0916093bfb83ca (diff) | |
download | rails-db26ace030f6704da6fc80bcc6cd00a2aee664ce.tar.gz rails-db26ace030f6704da6fc80bcc6cd00a2aee664ce.tar.bz2 rails-db26ace030f6704da6fc80bcc6cd00a2aee664ce.zip |
Ensure NoMethodError isn't raised when some of the nested eager loaded associations are empty [#1696 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 301b3a3b58..6d25b36aea 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1856,9 +1856,10 @@ module ActiveRecord def construct(parent, associations, joins, row) case associations when Symbol, String - while (join = joins.shift).reflection.name.to_s != associations.to_s - raise ConfigurationError, "Not Enough Associations" if joins.empty? - end + join = joins.detect{|j| j.reflection.name.to_s == associations.to_s && j.parent_table_name == parent.class.table_name } + raise(ConfigurationError, "No such association") if join.nil? + + joins.delete(join) construct_association(parent, join, row) when Array associations.each do |association| @@ -1866,7 +1867,11 @@ module ActiveRecord end when Hash associations.keys.sort{|a,b|a.to_s<=>b.to_s}.each do |name| - association = construct_association(parent, joins.shift, row) + join = joins.detect{|j| j.reflection.name.to_s == name.to_s && j.parent_table_name == parent.class.table_name } + raise(ConfigurationError, "No such association") if join.nil? + + association = construct_association(parent, join, row) + joins.delete(join) construct(association, associations[name], joins, row) if association end else |