Class: Forum

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/forum.rb

Overview

This model is used to represent a forum that can contain multiple forum topics, which are represented using ForumTopic objects. It has specified acts_as_content_node from Acts::ContentNode::ClassMethods.

Specification

Attributes

  • title - The title of the forum.

  • description - The description of the forum.

Preconditions

  • Requires the presence of title.

  • Requires the uniqueness of title.

Child/parent type constraints

* A +Forum+ only accepts +ForumTopic+ children.

Instance Method Summary (collapse)

Instance Method Details

- (Object) content_tokens

Returns the description as the token for indexing.



59
60
61
# File 'app/models/forum.rb', line 59

def content_tokens
  description
end

- (Object) find_last_updated_forum_threads(limit = 5, args = {})

Finds the limit last updated ForumThread grandchildren.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/forum.rb', line 41

def find_last_updated_forum_threads(limit = 5, args = {})
  return [] if limit <= 0
  # Custom SQL query to minimize performance hit
  # TODO: Not too keen on the INNER JOINs here, any way to avoid these? DB caching of created_at?
  ForumThread.find(:all,
    {
      :select     => 'forum_threads.id, forum_threads.title, forum_threads.forum_topic_id, MAX(forum_posts.created_at) AS last_update_date', 
      :from       => '(forum_threads ',
      :joins      => 'INNER JOIN forum_topics ON forum_threads.forum_topic_id = forum_topics.id) INNER JOIN forum_posts ON forum_posts.forum_thread_id = forum_threads.id',
      :conditions => { :forum_topic_id => forum_topics },
      :group      => 'forum_threads.id, forum_threads.title, forum_threads.forum_topic_id', 
      :limit      => limit,
      :order      => 'last_update_date DESC'
    }.merge(args)
  )
end