Skip to content

Commit

Permalink
narrowed down includes on search.
Browse files Browse the repository at this point in the history
There's a bug that crops up in rails >= 2.1 ...
"Not unique table/alias" forums

This is less effcient, but ought to work for the time being
  • Loading branch information
Chris Flipse committed Sep 25, 2008
1 parent 0f1140c commit dafd185
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ class Post < ActiveRecord::Base

attr_accessible :body

def forum_name
forum.name
end

def self.search(query, options = {})
options[:conditions] ||= ["LOWER(#{Post.table_name}.body) LIKE ?", "%#{query}%"] unless query.blank?
options[:select] ||= "#{Post.table_name}.*, #{Topic.table_name}.title as topic_title, #{Forum.table_name}.name as forum_name"
options[:joins] ||= "inner join #{Topic.table_name} on #{Post.table_name}.topic_id = #{Topic.table_name}.id inner join #{Forum.table_name} on #{Topic.table_name}.forum_id = #{Forum.table_name}.id"
options[:select] ||= "#{Post.table_name}.*, #{Topic.table_name}.title as topic_title" #, #{Forum.table_name}.name as forum_name"
options[:joins] ||= "inner join #{Topic.table_name} on #{Post.table_name}.topic_id = #{Topic.table_name}.id" #inner join #{Forum.table_name} on #{Topic.table_name}.forum_id = #{Forum.table_name}.id"
options[:order] ||= "#{Post.table_name}.created_at DESC"
options[:count] ||= {:select => "#{Post.table_name}.id"}
paginate options
Expand All @@ -39,4 +43,4 @@ def update_cached_fields
def topic_is_not_locked
errors.add_to_base("Topic is locked") if topic && topic.locked? && topic.posts_count > 0
end
end
end

0 comments on commit dafd185

Please sign in to comment.