Add resource_class to Her::Model::ORM #279
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From commit message
Different APIs may have different conventions for searching for relations. For
example, an API may not use query params for
#where
like searches. In thesecases, it might be useful to have a model use a specialized
Relation
classthat contains these rules. This commit adds two methods to
Her::Model::ORM
:.use_relation(klass)
specifies the relation class to be used.relation_class
gets the used relation classInternally, the ORM module uses the defined relation (defaulting to
Her::Model::Relation
) for setting up queries.PR notes
I put in this logic because I was using a non-Rails API that had quirky conventions. This API did not use query params for
GET /:resource
searches, but instead had a custom resource path to which onePOST
ed a query object. In order to haveHer
accommodate this, I either needed to monkey patchHer::Model::Relation
, maintain a separate fork ofHer
with a modifiedRelation
class, or include this functionality, to set your own relation class (which could inheritHer::Model::Relation
and only override what it needed to).