Method: Contentstack::Entry#only
- Defined in:
- lib/contentstack/entry.rb
#only(fields, fields_with_base = nil) ⇒ Contentstack::Entry
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
@entry = @stack.content_type('category').entry(entry_uid)
@entry.only(['title', 'description'])
# Query product and include only the title and description from category reference
@entry = @stack.content_type('product').entry(entry_uid)
@entry.include_reference('category')
.only('category', ['title', 'description'])
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/contentstack/entry.rb', line 42 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 |