Method: JSONAPI::Resource.find_by_key

Defined in:
lib/jsonapi/resource.rb

.find_by_key(key, options = {}) ⇒ Object



762
763
764
765
766
767
768
769
# File 'lib/jsonapi/resource.rb', line 762

def find_by_key(key, options = {})
  context = options[:context]
  records = records(options)
  records = apply_includes(records, options)
  model = records.where({_primary_key => key}).first
  fail JSONAPI::Exceptions::RecordNotFound.new(key) if model.nil?
  self.resource_for_model(model).new(model, context)
end