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)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/glue/taggable.rb', line 145 def find_with_any_tag(*names) info = ogmanager.store.join_table_info(self, Tag) count = names.size names = names.map { |n| ogmanager.store.quote(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)
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/glue/taggable.rb', line 122 def (*names) info = ogmanager.store.join_table_info(self, Tag) count = names.size names = names.map { |n| ogmanager.store.quote(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 |