her icon indicating copy to clipboard operation
her copied to clipboard

Add resource_class to Her::Model::ORM

Open kindrowboat opened this issue 11 years ago • 0 comments

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).

kindrowboat avatar Aug 11 '14 23:08 kindrowboat