How do I get a list of articles associated with a particular tag stored in tag_list?

to-doc
Tags: #<Tag:0x00007f81c606bd38>

(Danny) #1

How do I get a list of articles associated with a particular tag stored in tag_list?


Unable to assign Article to blog when Blog (Parent) is created after Article
(Aaron Russell) #2

The TagList field does add a few methods to your node class to help exactly with this…

Assuming the following:

class Page < PushType::Node
  field :tags, :tag_list
end

The TagList field dynamically defines the following methods. The method names are determined by the field name, so if you haven’t called the field “tags” then adjust the following method names accordingly.

# Return all Page nodes which contains all the passed tags
Page.with_all_tags('foo', 'bar', 'baz')

# Return all Page nodes which contains any of the passed tags
Page.with_any_tags('foo', 'bar', 'baz')

# Return an array of all tags from all Page nodes
Page.all_tags

(Danny) #3

Can you add this answer to the documentation? That would be really handy :stuck_out_tongue: