Retrieve Topics based on custom field?

The way to do this is

  1. On the client: Add a topic query param using api.addDiscoveryQueryParam

  2. On the server: Filter topic queries by the param using add_custom_filter in the TopicQuery class (see lib/topic_query)

The add_custom_filter callback will look a bit like this

::TopicQuery.add_custom_filter(:field_name) do |topics, query|
  if query.options[:field_name]
    topics.where("topics.id in (
      SELECT topic_id FROM topic_custom_fields
      WHERE (name = 'field_name')
      AND value = '#{query.options[:field_name]}'
    )")
  else
    topics
  end
end
3 Likes