From ed5168e4c98ec7d4af6bceaa25d0a36c2777cc5d Mon Sep 17 00:00:00 2001 From: hukl Date: Fri, 27 Feb 2009 16:08:31 +0100 Subject: modified the aggregate method to take only head / published pages into account --- app/models/page.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index aba974a..ec2198c 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -21,21 +21,26 @@ class Page < ActiveRecord::Base # The Page.aggregate method comes with a defaults hash. These options are # partially or entirely overwritten by the options hash. Afterwards the merged # parameters are used to query the DB for Pages matching these parameters. + # The aggregation only takes published pages into account. def self.aggregate options defaults = { :tags => "", :limit => 20, - :order_by => "id", + :order_by => "pages.id", :order_direction => "ASC" } options = defaults.merge options - pages = Page.find_tagged_with( - options[:tags].gsub(/\s/, ", "), + pages = Page.find_all_tagged_with( + options[:tags].gsub(/\s/, ", "), :match_all => true, - :order => "#{options[:order_by]} #{options[:order_direction]}") + :order => "#{options[:order_by]} #{options[:order_direction]}", + :include => :node, + :conditions => ["nodes.head_id = pages.id"] + ) + end # Instance Methods -- cgit v1.3