summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorhukl <hukl@eight.local>2009-02-02 23:46:46 +0100
committerhukl <hukl@eight.local>2009-02-02 23:46:46 +0100
commit1bbeefe805efba28ef9c237a1c27f3f1ce1d5dc0 (patch)
treeaf9103e8e23b097a930f6fa6930dca470d657043 /app/models
parent1c8bcc58d410db6d7eb5f1629813f08f78f47fa1 (diff)
refactored the whole tagging thing. now using
acts_as_taggable_on_steroids instead of a homebrew solution
Diffstat (limited to 'app/models')
-rw-r--r--app/models/flag.rb3
-rw-r--r--app/models/page.rb41
2 files changed, 4 insertions, 40 deletions
diff --git a/app/models/flag.rb b/app/models/flag.rb
deleted file mode 100644
index 6d67377..0000000
--- a/app/models/flag.rb
+++ /dev/null
@@ -1,3 +0,0 @@
1class Flag < ActiveRecord::Base
2 has_and_belongs_to_many :pages
3end
diff --git a/app/models/page.rb b/app/models/page.rb
index e1bddb2..5908029 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -1,39 +1,9 @@
1# Alternativ queries for the named_scope with one or two inner joins.
2# Loading the Flags themselves would be another query.
3# Could be faster on larger data sets.
4#
5# Single Join:
6#
7# Page.find(
8# :all,
9# :joins => 'JOIN flags_pages on pages.id = flags_pages.page_id',
10# :include => :flags,
11# :conditions => ['flags_pages.flag_id IN (?)', [1,2]]
12# )
13# Two inner joins:
14#
15# Page.find(
16# :all,
17# :joins => :flags_pages,
18# :conditions => ['flags_pages.flag_id IN (?)', [1,2]]
19# )
20#
21# Page.find_by_sql("select p.* from pages p JOIN flags_pages f on p.id = f.page_id where (f.flag_id IN (1,2))")
22
23class Page < ActiveRecord::Base 1class Page < ActiveRecord::Base
24 2
25 belongs_to :node 3 belongs_to :node
26 has_and_belongs_to_many :flags
27
28 acts_as_list :column => :revision, :scope => :node_id
29 4
30 named_scope :with_flags, lambda {|flag_names| 5 acts_as_taggable
31 if (flags = Flag.find_all_by_name(flag_names)).empty? 6 acts_as_list :column => :revision, :scope => :node_id
32 {}
33 else
34 {:include => :flags, :conditions => ['flags_pages.flag_id IN (?)', flags.map(&:id)] }
35 end
36 }
37 7
38 # <aggregate 8 # <aggregate
39 # flags="updates pressemitteilungen" 9 # flags="updates pressemitteilungen"
@@ -51,10 +21,7 @@ class Page < ActiveRecord::Base
51 } 21 }
52 22
53 options = defaults.merge options 23 options = defaults.merge options
54 24 debugger
55 pages = Page.with_flags(options[:flags].split(/\s/)).all( 25 pages = Page.find_tagged_with(options[:flags], :match_all => true)
56 :limit => options[:limit],
57 :order => "#{options[:order_by]} #{options[:order_direction]}"
58 )
59 end 26 end
60end \ No newline at end of file 27end \ No newline at end of file