Updated Rake tasks and test, spec to reflect change in how Merb environments
[merb_mart.git] / app / models / section.rb
blob454d7fc189570ca32354615ec5a956e01ac66470
1 # A section is an organizational unit for content nodes.
3 # Sections can be applied to pages or snippets, but really are
4 # only meant for blogs.
6 class Section
7   
8   include DataMapper::Persistable
9   include DataMapper::Is::Tree
10   
11   has_and_belongs_to_many :content_nodes
12   has_and_belongs_to_many :blogs,
13     :join_table => 'content_nodes_sections',
14     :association_foreign_key => 'content_node_id',
15     :conditions => "content_nodes.type = 'Blog'",
16     :order => 'display_on DESC'
17     
18   property :name, :string, :length => 100, :default => "", :nullable => false
19   property :rank, :integer
20   #property :parent_id --> 
21     
22   #validates_presence_of :name
23   #validates_uniqueness_of :name
24   is_a_tree :order => 'rank' # '-rank DESC'
25   
26   # Most used finder function for tags.
27   # Selects by alpha sort.
28   def self.find_alpha
29     all  #:order => 'name ASC')
30   end
31   
32   # Finds ordered parent tags.
33   def self.find_ordered_parents
34     all(:conditions => "parent_id IS NULL OR parent_id = 0")
35       #:order => "-rank DESC"
36   end
37   
38   # Returns the number of products tagged with this item
39   def content_count
40     @cached_content_count ||= self.content_nodes.count
41   end
42   
43 end