Method: Contentstack::Query#only
- Defined in:
- lib/contentstack/query.rb
#only(fields, fields_with_base = nil) ⇒ Contentstack::Query
Specifies an array of ‘only’ keys in BASE object that would be ‘included’ in the response.
Example
# Include only title and description field in response
@query = @stack.content_type('category').query
@query.only(['title', 'description'])
# Query product and include only the title and description from category reference
@query = @stack.content_type('product').query
@query.include_reference('category')
.only('category', ['title', 'description'])
426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/contentstack/query.rb', line 426 def only(fields, fields_with_base=nil) q = {} if [Array, String].include?(fields_with_base.class) fields_with_base = [fields_with_base] if fields_with_base.class == String q[fields.to_sym] = fields_with_base else fields = [fields] if fields.class == String q = {BASE: fields} end @query[:only] = q self end |