Permalink
Browse files

narrowed down includes on search.

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...
1 parent 0f1140c commit dafd185a225877227292a96bb3cba1ee66d8c1ec Chris Flipse committed Sep 25, 2008
Showing with 7 additions and 3 deletions.
  1. +7 −3 app/models/post.rb
View
@@ -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
@@ -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.