Module: Glue::Taggable::ClassMethods
- Defined in:
- lib/glue/taggable.rb
Instance Method Summary collapse
-
#find_with_any_tag(*names) ⇒ Object
Find objects with any of the provided tags.
-
#find_with_tags(*names) ⇒ Object
(also: #find_with_tag)
Find objects with all of the provided tags.
Instance Method Details
#find_with_any_tag(*names) ⇒ Object
Find objects with any of the provided tags. UNION (OR)
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/glue/taggable.rb', line 127 def find_with_any_tag(*names) info = ogmanager.store.join_table_info(self, tag) count = names.size names = names.map { |n| "'#{n}'" }.join(',') sql = %{ SELECT o.* FROM #{info[:first_table]} AS o, #{info[:second_table]} as t, #{info[:table]} as j WHERE o.oid = j.#{info[:first_key]} AND t.oid = j.#{info[:second_key]} AND (t.name in (#{names})) GROUP BY o.oid } return self.select(sql) end |
#find_with_tags(*names) ⇒ Object Also known as: find_with_tag
Find objects with all of the provided tags. INTERSECTION (AND)
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/glue/taggable.rb', line 104 def (*names) info = ogmanager.store.join_table_info(self, Tag) count = names.size names = names.map { |n| "'#{n}'" }.join(',') sql = %{ SELECT o.* FROM #{info[:first_table]} AS o, #{info[:second_table]} as t, #{info[:table]} as j WHERE o.oid = j.#{info[:first_key]} AND t.oid = j.#{info[:second_key]} AND (t.name in (#{names})) GROUP BY o.oid HAVING COUNT(o.oid) = #{count}; } return self.select(sql) end |