Module: Polytag::ClassMethods
- Defined in:
- lib/polytag.rb
Instance Method Summary collapse
-
#has_tags(*tags) ⇒ Object
(also: #has_tag)
Get records with tags.
- #in_tag_group(_tag_group = {}) ⇒ Object
- #in_tag_groups(*tag_groups) ⇒ Object
Instance Method Details
#has_tags(*tags) ⇒ Object Also known as: has_tag
Get records with tags
62 63 64 |
# File 'lib/polytag.rb', line 62 def (*) includes(polytag_tag_relations: :polytag_tag).references(:polytag_tags).where("polytag_tags.name IN (?)", ).group("#{table_name}.id") end |
#in_tag_group(_tag_group = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/polytag.rb', line 68 def in_tag_group(_tag_group = {}) if _tag_group[:group_ids] tag_groups = _tag_group[:group_ids] else tag_groups = Polytag::TagGroup.select('polytag_tag_groups.id').search_by_hash(_tag_group).map{ |tg| tg.try(:id) }.flatten end return tag_groups if _tag_group[:multi] includes(polytag_tag_relations: :polytag_tag).references(:polytag_tags).where('polytag_tags.polytag_tag_group_id IN (?)', tag_groups) end |
#in_tag_groups(*tag_groups) ⇒ Object
80 81 82 83 |
# File 'lib/polytag.rb', line 80 def in_tag_groups(*tag_groups) tag_groups = tag_groups.map{ |tg| in_tag_group(tg.merge(multi: true)) }.flatten.compact in_tag_group(group_ids: tag_groups) end |