Skip to content

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

@mohammad-goldast

Description

@mohammad-goldast

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",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions