Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource_class to Her::Model::ORM #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kindrowboat
Copy link
Contributor

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 these
cases, it might be useful to have a model use a specialized Relation class
that 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 class

Internally, 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 one POSTed a query object. In order to have Her accommodate this, I either needed to monkey patch Her::Model::Relation, maintain a separate fork of Her with a modified Relation class, or include this functionality, to set your own relation class (which could inherit Her::Model::Relation and only override what it needed to).

Different APIs may have different conventions for searching for relations.  For
example, an API may not use query params for `#where` like searches. In these
cases, it might be useful to have a model use a specialized `Relation` class
that 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 class

Internally, the ORM module uses the defined relation (defaulting to
`Her::Model::Relation`) for setting up queries.
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.

None yet

1 participant