Skip to content

Conversation

@UseTheFork
Copy link
Collaborator

Purpose of this Pull Request

This pull request adds a "get" implementation to the models.

Reference

Description

Since "get" is a reserved term in Eloquent, I've named the method document instead. This PR introduces two new methods to all models:

  • documentOrNew
  • documentOrFail

Both methods accept an id as their only parameter and directly utilize the Elasticsearch get method to retrieve a document. The documentOrFail method will throw an exception if the document is not found, whereas documentOrNew will return a new instance of the model with the id set to the one you attempted to retrieve.

Justification

I often store documents directly and know the exact id values. While findOrNew exists, these new methods have less overhead since they do not perform a search for the document; they directly retrieve it using Elasticsearch's get method.

…ntOrFail`

- Introduced `documentOrNew` and `documentOrFail` methods in `Builder` for better document management.
- Enhanced `Connection` with `getDocument` method for fetching documents by ID.
- Added `processGetDocument` and `_returnDocument` methods to `Bridge` for document retrieval.
- Implemented `_sanitizeGetResponse` for processing single document responses.
- Included tests for `documentOrNew` and `documentOrFail` scenarios.

Because fetching documents should never feel like hide-and-seek! 😎
@UseTheFork UseTheFork closed this Sep 17, 2024
@UseTheFork UseTheFork deleted the feature/documentOr branch September 18, 2024 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant