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

I got 'Cannot read property 'get' of undefined' error on a simple join #89

Closed
SharpBCD opened this issue Mar 26, 2020 · 4 comments
Closed

Comments

@SharpBCD
Copy link

most probably I do something wrong.
I have a table customers and one with address.
query = { '$eager': 'address' } or { '$joinRelation': 'address' } returns the error.
Note: bellow code works:

	const query2 = context.service.createQuery(context.params.query);
	query2.select('*').from('customers').leftJoin('address', 'address.id', 'customers.address_id');

	context.params.objection = query2;
	return context;

here is my customers.model:

	static get relationMappings() {
		const Address =  require('./address.model')();
		return {
			address: {
				relation  : Model.BelongsToOneRelation,
				modelClass: Address,
				join      : {
					to: 'address.id',
					from  : 'customers.address_id'
				}
			}
		};
	}

so what do I do wrong?

@dekelev
Copy link
Member

dekelev commented Mar 27, 2020

Please share the actual error message and a full example of the service call.

@SharpBCD
Copy link
Author

Here is the code, it is in a hook in before-find and get

	const query = context.params.query;
	query.$eager = 'address';
	context.params.query = query;

The error is:

GeneralError {type: "FeathersError", name: "GeneralError", message: "Cannot read property 'get' of undefined", code: 500, className: "general-error", …}
type: "FeathersError"
name: "GeneralError"
message: "Cannot read property 'get' of undefined"
code: 500
className: "general-error"
data: undefined
errors: {}
hook: {type: "before", arguments: Array(0), service: {…}, app: {…}, method: "find", …}
stack: "GeneralError: Cannot read property 'get' of undefined↵    at new GeneralError (webpack-internal:///./node_modules/@feathersjs/errors/lib/index.js:170:17)↵    at Object.convert (webpack-internal:///./node_modules/@feathersjs/errors/lib/index.js:239:7)↵    at Socket.eval (webpack-internal:///./node_modules/@feathersjs/transport-commons/lib/client.js:67:34)↵    at Socket.onack (webpack-internal:///./node_modules/socket.io-client/lib/socket.js:319:9)↵    at Socket.onpacket (webpack-internal:///./node_modules/socket.io-client/lib/socket.js:244:12)↵    at Manager.eval (webpack-internal:///./node_modules/component-bind/index.js:21:15)↵    at Manager.Emitter.emit (webpack-internal:///./node_modules/component-emitter/index.js:133:20)↵    at Manager.ondecoded (webpack-internal:///./node_modules/socket.io-client/lib/manager.js:345:8)↵    at Decoder.eval (webpack-internal:///./node_modules/component-bind/index.js:21:15)↵    at Decoder.Emitter.emit (webpack-internal:///./node_modules/component-emitter/index.js:133:20)"
__proto__: FeathersError

@dekelev
Copy link
Member

dekelev commented Mar 31, 2020

I see in the error stack that socket.io-client is used in your test, so you're probably testing this with a client.

For testing purposes, you can try to call the service internally in the server and see if it works.

Your error message could be thrown before even reaching the hook. you can debug and see if the hook is actually executed.

My guess is that this error has nothing to do with feathers-objection. it looks like an error you would get if a service doesn't exists, e.g. not loaded, or if you're are calling a service by name with a typo or missing something, like API version prefix.

@dekelev dekelev closed this as completed Apr 3, 2020
@SharpBCD
Copy link
Author

You may be right. I did not had the export class declaration as in your example. Tried to modify it but I got an babel error but that's not an objections error. Meanwhile I solve it with another approach, may surf back to it later.
Thanks for support.

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