Skip to content

Commit

Permalink
Added new eagerOptions params operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekel Barzilay committed Feb 28, 2020
1 parent fc129c7 commit 9f910ea
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ Note that all this eager related options are optional.
- **`mergeAllowEager`** - Will merge the given expression to the existing expression from the `allowEager` service option.
See [`allowGraph`](https://vincit.github.io/objection.js/api/query-builder/eager-methods.html#allowgraph)
documentation.

- **`eagerOptions`** - Options object to use with `$eager` and `$joinEager` query operators.
See [`GraphOptions`](https://vincit.github.io/objection.js/api/types/#type-graphoptions)
documentation.

### Composite primary keys

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "feathers-objection",
"description": "A service plugin for ObjectionJS an ORM based on KnexJS",
"version": "5.0.0",
"version": "5.0.1",
"homepage": "https://github.com/feathersjs-ecosystem/feathers-objection",
"keywords": [
"feathers",
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class Service extends AdapterService {
createQuery (params = {}) {
const { filters, query } = this.filterQuery(params);
const q = this._createQuery(params).skipUndefined();
const eagerOptions = params.eagerOptions || {};

if (this.allowedEager) { q.allowGraph(this.allowedEager); }

Expand All @@ -271,13 +272,13 @@ class Service extends AdapterService {

// $eager for Objection eager queries
if (query && query.$eager) {
q.withGraphFetched(query.$eager);
q.withGraphFetched(query.$eager, eagerOptions);

delete query.$eager;
}

if (query && query.$joinEager) {
q.withGraphJoined(query.$joinEager);
q.withGraphJoined(query.$joinEager, eagerOptions);

delete query.$joinEager;
}
Expand All @@ -291,7 +292,7 @@ class Service extends AdapterService {
}

if (query && query.$mergeEager) {
q[query.$joinEager ? 'withGraphJoined' : 'withGraphFetched'](query.$mergeEager);
q[query.$joinEager ? 'withGraphJoined' : 'withGraphFetched'](query.$mergeEager, eagerOptions);

delete query.$mergeEager;
}
Expand Down

0 comments on commit 9f910ea

Please sign in to comment.