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

Associations, "hasOne" , pkgCat.getQuest is not a function #797

Open
mohammad-goldast opened this issue Jul 21, 2017 · 0 comments
Open

Associations, "hasOne" , pkgCat.getQuest is not a function #797

mohammad-goldast opened this issue Jul 21, 2017 · 0 comments

Comments

@mohammad-goldast
Copy link

mohammad-goldast commented Jul 21, 2017

Hi, im new in ORM, and i have a problem with "hasOne" .
I defined this models in Models.js :
`
module.exports = function(db, cb) {
db.define('Users', {
fullName : String,
userName : String,
passWord : String,
phoneNum : String,
codeMelli : String,
state : String,
pkgId : Number,
pkgCatId : Number
});
db.define('Pkg', {
name : String,
});
db.define('pkgCat', {
name : String,
parentId : Number,
pkgId : Number
});
db.define('Questions', {
subject : String,
pkgCatId : Number
});
db.define('Answers', {
questId : String,
userId : Number
});
Questions.hasOne('owner', pkgCat, {reverse: 'quest'})
return cb();
}

`
so when i want to get all record in Questions table , i see this error :

TypeError: pkgCat.getQuest is not a function at Object.module.exports.homePage (/home/mohammad/workSpace/officialPj/omraneManavi/db/api.js:18:16) at /home/mohammad/workSpace/officialPj/omraneManavi/routes/apiRouter.js:18:11 at Layer.handle [as handle_request] (/home/mohammad/workSpace/officialPj/omraneManavi/node_modules/express/lib/router/layer.js:95:5) at next (/home/mohammad/workSpace/officialPj/omraneManavi/node_modules/express/lib/router/route.js:137:1....

and i have a query like this :
pkgCat.getQuest(function(err, pnt) { console.log(pnt); })
also i have a config file , like this :
`
app.use(orm.express("mysql://root:0201243@localhost/omraneManaviApp", {
define: function (db, models, next) {
db.use(paging);
db.load('./models', function(err) {
Users = db.models.users;
Pkg = db.models.pkg;
pkgCat = db.models.pkgCat;
Questions = db.models.Questions;
Answers = db.models.Answers;
});

    db.sync();
    console.log('connected mysql');

    next();   

}

}));
`

Does anyone know why this happens? Or how to solve this? Thanks!

Versions:
"node": "4.2.6",
"mysql": "^2.13.0",
"orm": "^3.2.4",

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

1 participant