From d0c3cd743e8500f643ff54b93e4a599c7e16b9d1 Mon Sep 17 00:00:00 2001 From: hukl Date: Mon, 2 Feb 2009 21:02:18 +0100 Subject: more comments with alternate queries --- app/models/page.rb | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index d5d888f..fee20a8 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -5,6 +5,24 @@ class Page < ActiveRecord::Base acts_as_list :column => :revision, :scope => :node_id + # Alternativ Queries with one or two inner joins. Loading the Flags themselves + # would be another query. Could be faster on larger data sets. + # + # Single Join: + # + # Page.find( + # :all, + # :joins => 'JOIN flags_pages on pages.id = flags_pages.page_id', + # :include => :flags, + # :conditions => ['flags_pages.flag_id IN (?)', [1,2]] + # ) + # Two inner joins: + # + # Page.find( + # :all, + # :joins => :flags_pages, + # :conditions => ['flags_pages.flag_id IN (?)', [1,2]] + # ) named_scope :with_flags, lambda {|flag_names| if (flags = Flag.find_all_by_name(flag_names)).empty? {} @@ -12,12 +30,9 @@ class Page < ActiveRecord::Base {:include => :flags, :conditions => ['flags_pages.flag_id IN (?)', flags.map(&:id)] } end } - - - + # "", - :path => "", :limit => 20, :order_by => "id", :order_direction => "ASC" @@ -34,7 +48,7 @@ class Page < ActiveRecord::Base options = defaults.merge options - pages = Page.all( + pages = Page.with_flags(options[:flags].split(/\s/)).all( :limit => options[:limit], :order => "#{options[:order_by]} #{options[:order_direction]}" ) -- cgit v1.3