summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorhukl <hukl@eight.local>2009-02-02 21:02:18 +0100
committerhukl <hukl@eight.local>2009-02-02 21:02:18 +0100
commitd0c3cd743e8500f643ff54b93e4a599c7e16b9d1 (patch)
tree851e9734323fa32780b4956acad6cadd70c07d6e /app
parentfa31c7b73d57183f5379d81bf17aaf45bea59daa (diff)
more comments with alternate queries
Diffstat (limited to 'app')
-rw-r--r--app/models/page.rb26
1 files 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
5 5
6 acts_as_list :column => :revision, :scope => :node_id 6 acts_as_list :column => :revision, :scope => :node_id
7 7
8 # Alternativ Queries with one or two inner joins. Loading the Flags themselves
9 # would be another query. Could be faster on larger data sets.
10 #
11 # Single Join:
12 #
13 # Page.find(
14 # :all,
15 # :joins => 'JOIN flags_pages on pages.id = flags_pages.page_id',
16 # :include => :flags,
17 # :conditions => ['flags_pages.flag_id IN (?)', [1,2]]
18 # )
19 # Two inner joins:
20 #
21 # Page.find(
22 # :all,
23 # :joins => :flags_pages,
24 # :conditions => ['flags_pages.flag_id IN (?)', [1,2]]
25 # )
8 named_scope :with_flags, lambda {|flag_names| 26 named_scope :with_flags, lambda {|flag_names|
9 if (flags = Flag.find_all_by_name(flag_names)).empty? 27 if (flags = Flag.find_all_by_name(flag_names)).empty?
10 {} 28 {}
@@ -12,12 +30,9 @@ class Page < ActiveRecord::Base
12 {:include => :flags, :conditions => ['flags_pages.flag_id IN (?)', flags.map(&:id)] } 30 {:include => :flags, :conditions => ['flags_pages.flag_id IN (?)', flags.map(&:id)] }
13 end 31 end
14 } 32 }
15 33
16
17
18 # <aggregate 34 # <aggregate
19 # flags="updates pressemitteilungen" 35 # flags="updates pressemitteilungen"
20 # path="updates/2009"
21 # limit="20" 36 # limit="20"
22 # order_by="published_at" 37 # order_by="published_at"
23 # order_direction="DESC" 38 # order_direction="DESC"
@@ -26,7 +41,6 @@ class Page < ActiveRecord::Base
26 41
27 defaults = { 42 defaults = {
28 :flags => "", 43 :flags => "",
29 :path => "",
30 :limit => 20, 44 :limit => 20,
31 :order_by => "id", 45 :order_by => "id",
32 :order_direction => "ASC" 46 :order_direction => "ASC"
@@ -34,7 +48,7 @@ class Page < ActiveRecord::Base
34 48
35 options = defaults.merge options 49 options = defaults.merge options
36 50
37 pages = Page.all( 51 pages = Page.with_flags(options[:flags].split(/\s/)).all(
38 :limit => options[:limit], 52 :limit => options[:limit],
39 :order => "#{options[:order_by]} #{options[:order_direction]}" 53 :order => "#{options[:order_by]} #{options[:order_direction]}"
40 ) 54 )