Skip to content

Commit

Permalink
Cache negative lookup when eagerly loading many_to_one associations w…
Browse files Browse the repository at this point in the history
…here no objects have an associated object
  • Loading branch information
jeremyevans committed Sep 20, 2008
1 parent ca7cc40 commit 8cf0d3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
=== HEAD === HEAD


* Cache negative lookup when eagerly loading many_to_one associations where no objects have an associated object (jeremyevans)

* Allow string keys to be used when using Dataset#multi_insert (jeremyevans) * Allow string keys to be used when using Dataset#multi_insert (jeremyevans)


* Fix join_table when doing the first join for a dataset where the first source is a dataset when using unqualified columns (jeremyevans) * Fix join_table when doing the first join for a dataset where the first source is a dataset when using unqualified columns (jeremyevans)
Expand Down
8 changes: 4 additions & 4 deletions lib/sequel_model/associations.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ def def_many_to_one(opts)
opts[:eager_loader] ||= proc do |key_hash, records, associations| opts[:eager_loader] ||= proc do |key_hash, records, associations|
h = key_hash[key] h = key_hash[key]
keys = h.keys keys = h.keys
# Default the cached association to nil, so any object that doesn't have it
# populated will have cached the negative lookup.
records.each{|object| object.associations[name] = nil}
# Skip eager loading if no objects have a foreign key for this association # Skip eager loading if no objects have a foreign key for this association
unless keys.empty? unless keys.empty?
# Default the cached association to nil, so any object that doesn't have it model.eager_loading_dataset(opts, opts.associated_class.filter(opts.associated_primary_key.qualify(opts.associated_class.table_name)=>keys), opts.select, associations).all do |assoc_record|
# populated will have cached the negative lookup.
records.each{|object| object.associations[name] = nil}
model.eager_loading_dataset(opts, opts.associated_class.filter(opts.associated_primary_key.qualify(opts.associated_class.table_name)=>keys), opts.select, associations).all do |assoc_record|
next unless objects = h[assoc_record.pk] next unless objects = h[assoc_record.pk]
objects.each{|object| object.associations[name] = assoc_record} objects.each{|object| object.associations[name] = assoc_record}
end end
Expand Down

0 comments on commit 8cf0d3a

Please sign in to comment.