Permalink
Browse files

Eager load

  • Loading branch information...
1 parent 75e6e5b commit 5f39fbb081b13af7d1859c5cc74897497aa6748b @radar radar committed Feb 25, 2009
Showing with 3 additions and 3 deletions.
  1. +3 −3 leaves/logga/controller.rb
@@ -127,15 +127,15 @@ def find_constant(stem, sender, reply_to, name, entry=nil, opts={})
# Find by specific name.
puts name.inspect
puts Constant.find_by_name("Array").inspect
- constants = Constant.find_all_by_name(name)
+ constants = Constant.find_all_by_name(name, :include => "entries")
# Find by name beginning with <blah>.
- constants = Constant.all(:conditions => ["name LIKE ?", name + "%"]) if constants.empty?
+ constants = Constant.all(:conditions => ["name LIKE ?", name + "%"], :include => "entries") if constants.empty?
# Find by fuzzy.
constants = Constant.find_by_sql("select * from constants where name LIKE '%#{for_sql(name.split("").join("%"))}%'") if constants.empty?
if constants.size > 1
# Narrow it down to the constants that only contain the entry we are looking for.
if !entry.nil?
- constants = constants.select { |constant| puts constant.entries.inspect; !constant.entries.find_by_name(entry).nil? }
+ constants = constants.select { |constant| puts !constant.entries.find_by_name(entry).nil? }
return [constants, constants.size]
else
display_constants(stem, sender, reply_to, constants, opts={})

0 comments on commit 5f39fbb

Please sign in to comment.