Method: Contentstack::Query#except

Defined in:
lib/contentstack/query.rb

#except(fields, fields_with_base = nil) ⇒ Contentstack::Query

Specifies list of field uids that would be ‘excluded’ from the response.

Example

# Exclude 'description' field in response
@query = @stack.content_type('category').query
@query.except(['description'])

# Query product and exclude the 'description' from category reference
@query = @stack.content_type('product').query
@query.include_reference('category')
      .except('category', ['description'])

Parameters:

  • fields (Array)

    Array of field uid which get ‘excluded’ from the response.

  • fields_with_base (Array) (defaults to: nil)

    Can be used to denote ‘except’ fields of the reference class

Returns:



456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/contentstack/query.rb', line 456

def except(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[:except] = q
  self
end