feathersjs-ecosystem / feathers-objection

Feathers database adapter for Objection.js, an ORM based on KnexJS SQL query builder for Postgres, Redshift, MSSQL, MySQL, MariaDB, SQLite3, and Oracle. Forked from feathers-knex.
MIT License
98 stars 48 forks source link

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

Closed SharpBCD closed 4 years ago

SharpBCD commented 4 years ago

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 commented 4 years ago

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

SharpBCD commented 4 years ago

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 commented 4 years ago

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.

SharpBCD commented 4 years ago

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.