dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

Cannot read property 'mapsTo' of undefined #834

Closed TongDaDa closed 5 years ago

TongDaDa commented 5 years ago

Use my SQL tool to query it as follows

screen shot 2018-07-16 at 3 33 56 pm

But use "orm" an unknown error has occurred

TypeError: Cannot read property 'mapsTo' of undefined
    at Object.exports.transformOrderPropertyNames (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_orm@5.0.2@orm/lib/Utilities.js:330:37)
    at chainRun (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_orm@5.0.2@orm/lib/ChainFind.js:31:23)
    at Object.run (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_orm@5.0.2@orm/lib/ChainFind.js:224:7)
    at Function.Model.model.find (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_orm@5.0.2@orm/lib/Model.js:441:13)
    at generateAudio (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/controller/v1/generateAudio.js:19:36)
    at Layer.handle [as handle_request] (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/layer.js:95:5)
    at next (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/route.js:137:13)
    at Route.dispatch (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/layer.js:95:5)
    at /Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/index.js:281:22
    at Function.process_params (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/index.js:335:12)
    at next (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/index.js:275:10)
    at Function.handle (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/index.js:174:3)
    at router (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/layer.js:95:5)
    at trim_prefix (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_express@4.16.3@express/lib/router/index.js:317:13)
TypeError: Cannot read property 'mapsTo' of undefined
    at Object.exports.transformOrderPropertyNames (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_orm@5.0.2@orm/lib/Utilities.js:330:37)
    at chainRun (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_orm@5.0.2@orm/lib/ChainFind.js:31:23)
    at Object.run (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_orm@5.0.2@orm/lib/ChainFind.js:224:7)
    at Function.Model.model.find (/Applications/XAMPP/xamppfiles/htdocs/woeks/striving/word_word_pronounced/node_modules/_orm@5.0.2@orm/lib/Model.js:441:13)
dxg commented 5 years ago

Without code showing how this can be reproduced, this can't be fixed.

TongDaDa commented 5 years ago

@dxg sorry, I forgot it...

req.models.new_word_manage.where(`SELECT * FROM new_word_manage WHERE create_time BETWEEN "2018-07-15" AND "2018-07-16"`, (err, word) => {
            if (err) throw err;
            console.log(word);
            res.send("asdasd")
        });
dxg commented 5 years ago

I don't think you can pass SQL with a SELECT directly to a .where like that. I also recommend using the provided finders: https://github.com/dresende/node-orm2#conditions to build the query for you - it'll avoid any sql injection problems.