summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <hukl@eight.local>2009-02-02 22:29:35 +0100
committerhukl <hukl@eight.local>2009-02-02 22:29:35 +0100
commit52cdcb876c5f719c543e8d6efdcdc9dde759218a (patch)
tree74039934a3f2f1dede44ff4b9e60bd294457426f
parenta5d0690d323b2f45fb4210470461b35ebe31e826 (diff)
comments on top of the class to keep the class
itself clean
-rw-r--r--app/models/page.rb42
1 files changed, 23 insertions, 19 deletions
diff --git a/app/models/page.rb b/app/models/page.rb
index fee20a8..e1bddb2 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -1,28 +1,32 @@
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
1class Page < ActiveRecord::Base 23class Page < ActiveRecord::Base
2 24
3 belongs_to :node 25 belongs_to :node
4 has_and_belongs_to_many :flags 26 has_and_belongs_to_many :flags
5 27
6 acts_as_list :column => :revision, :scope => :node_id 28 acts_as_list :column => :revision, :scope => :node_id
7 29
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 # )
26 named_scope :with_flags, lambda {|flag_names| 30 named_scope :with_flags, lambda {|flag_names|
27 if (flags = Flag.find_all_by_name(flag_names)).empty? 31 if (flags = Flag.find_all_by_name(flag_names)).empty?
28 {} 32 {}