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

Loading nested relations #9

Open
matt-dalton opened this issue Mar 18, 2017 · 1 comment
Open

Loading nested relations #9

matt-dalton opened this issue Mar 18, 2017 · 1 comment

Comments

@matt-dalton
Copy link

Thanks for this library!

I might have missed something, but is it possible to load nested relations (as you would in bookshelf)?

e.g. /users?load=things,things.morethings,things.moreThings.moreNestedThings

Doing so for me errors in the getWithRelatedArray function:

TypeError: Cannot read property 'before' of undefined
<br> &nbsp; &nbsp;at Builder.relObj.(anonymous function)  (/Users/me/projects/talisker/node_modules/kalamata/src/index.js:432:38)
<br> &nbsp; &nbsp;at selectConstraints (/Users/me/projects/talisker/node_modules/bookshelf/lib/relation.js:247:46)
<br> &nbsp; &nbsp;at Sync.&lt;anonymous&gt; (/Users/me/projects/talisker/node_modules/bookshelf/lib/sync.js:161:21)
<br> &nbsp; &nbsp;at PassThroughHandlerContext.finallyHandler (/Users/me/projects/talisker/node_modules/bluebird/js/release/finally.js:57:23)
<br> &nbsp; &nbsp;at PassThroughHandlerContext.tryCatcher (/Users/me/projects/talisker/node_modules/bluebird/js/release/util.js:16:23)
<br> &nbsp; &nbsp;at Promise._settlePromiseFromHandler (/Users/me/projects/talisker/node_modules/bluebird/js/release/promise.js:512:31)
<br> &nbsp; &nbsp;at Promise._settlePromise (/Users/me/projects/talisker/node_modules/bluebird/js/release/promise.js:569:18)
<br> &nbsp; &nbsp;at Promise._settlePromise0 (/Users/me/projects/talisker/node_modules/bluebird/js/release/promise.js:614:10)
@nabilfreeman
Copy link

nabilfreeman commented Apr 27, 2017

Hey @matt-dalton , I also got this error today.

The way I patched it was to wrap the runHooks method in an if statement to check that it actually exists.

Before:

relObj[r] = function(qb) {
	runHooks(relHooks.before.getRelated, [req, res, qb]);
};

After:

relObj[r] = function(qb) {
	if(relHooks){
		runHooks(relHooks.before.getRelated, [req, res, qb]);
	}
};

(but I don't know what effect this has on the code - there might be a more serious underlying issue)

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

No branches or pull requests

2 participants