Skip to content

Support a catch-all modifier hook #1120

@lehni

Description

@lehni

I'd like to propose to add a way for a model class to provide a catch-all modifier for the case when a requested modifier isn't defined / found. Something along these lines:

class MyModel extends Model {
  ...

  static modifierNotFound(builder, modifier) {
    // Do something with the modifier and the query, and return the builder if it was
    // handled, nullish otherwise, indicating Objection should still throw an error.
    const { properties } = this.getJsonSchema()
    if (properties && modifier in properties) {
      return builder.select(modifier)
    }
  }
}

Optionally it could also just return a boolean.

I think this could open the door to many more creative uses of eager expressions and modifiers, and would be a pretty great feature that could be added with very little overhead. I'd be happy to create a PR for it.

@koskimas what do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions