def find_by(args)
      query = CloudDatastore.dataset.query name
      query.ancestor(args[:ancestor]) if args[:ancestor]
      query.limit(1)
      query.where(args.keys[0].to_s, '=', args.values[0])
      query_results = retry_on_exception { CloudDatastore.dataset.run query }
      from_entity(query_results.first)
    end
def find_by(args)
      query = CloudDatastore.dataset.query name
      query.ancestor(args[:ancestor]) if args[:ancestor]
      query.limit(1)
      query.where(args.keys[0].to_s, '=', args.values[0])
      query_results = retry_on_exception { CloudDatastore.dataset.run query }
      from_entity(query_results.first)
    end
Finds the first entity matching the specified condition.

 @param [Hash] args In which the key is the property and the value is the value to look for.
 @option args [Google::Cloud::Datastore::Key] :ancestor filter for inherited results

 @return [Model, nil] An ActiveModel object or nil.

 @example
   User.find_by(name: 'Joe')
   User.find_by(name: 'Bryce', ancestor: parent_key)