Skip to content

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.

1 participant