{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/3103","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/3103/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/3103/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/3103/events","html_url":"https://github.com/sequelize/sequelize/issues/3103","id":57306592,"number":3103,"title":"get[AS] is undefined in one to many model","user":{"login":"imsobear","id":2505411,"avatar_url":"https://avatars.githubusercontent.com/u/2505411?v=3","gravatar_id":"","url":"https://api.github.com/users/imsobear","html_url":"https://github.com/imsobear","followers_url":"https://api.github.com/users/imsobear/followers","following_url":"https://api.github.com/users/imsobear/following{/other_user}","gists_url":"https://api.github.com/users/imsobear/gists{/gist_id}","starred_url":"https://api.github.com/users/imsobear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imsobear/subscriptions","organizations_url":"https://api.github.com/users/imsobear/orgs","repos_url":"https://api.github.com/users/imsobear/repos","events_url":"https://api.github.com/users/imsobear/events{/privacy}","received_events_url":"https://api.github.com/users/imsobear/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-02-11T11:53:05Z","updated_at":"2015-02-12T19:24:24Z","closed_at":null,"body":"\r\nI have to models Task and Result, and a task has many results. I have declared `Task.hasMany(Result)` in my project, but the `task.getResults` is `undeined`. This problem confused me the whole day.\r\n\r\nand show the code:\r\n\r\n### model/index.js\r\n\r\n```javascript\r\nvar fs        = require('fs');\r\nvar path      = require('path');\r\nvar Sequelize = require('sequelize');\r\n\r\nvar config    = require('../config');\r\n\r\nvar sequelize = new Sequelize(config.database, config.username, config.password, {\r\n  dialect: 'mysql',\r\n  host: config.host,\r\n  port: config.port\r\n});\r\n\r\nvar db        = {};\r\n\r\nsequelize\r\n  .authenticate()\r\n  .complete(function(err) {\r\n    if (!!err) {\r\n      log.error('Unable to connect to the database:', err)\r\n    } else {\r\n      log.info('Connection has been established successfully.')\r\n    }\r\n  });\r\n\r\nfs\r\n  .readdirSync(__dirname)\r\n  .filter(function(file) {\r\n    return (file.indexOf('.') !== 0) && (file !== 'index.js');\r\n  })\r\n  .forEach(function(file) {\r\n    var model = sequelize['import'](path.join(__dirname, file));\r\n    db[model.name] = model;\r\n  });\r\n\r\nObject.keys(db).forEach(function(modelName) {\r\n  if ('associate' in db[modelName]) {\r\n    db[modelName].associate(db);\r\n  }\r\n});\r\n\r\ndb.sequelize = sequelize;\r\ndb.Sequelize = Sequelize;\r\n\r\nmodule.exports = db;\r\n```\r\n\r\n### model/task.js\r\n\r\n```javascript\r\nmodule.exports = function(sequelize, DataTypes) {\r\n  var Task = sequelize.define('Task', {\r\n  \tid: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true}\r\n  }, {\r\n  \ttableName: 'task',\r\n  \ttimestamps: true,\r\n  \tclassMethods: {\r\n  \t\tassociate: function (models) {\r\n  \t\t\tTask.hasMany(models.Result, {\r\n  \t\t\t\tforeignKey: 'task_id'\r\n   \t\t\t});\r\n  \t\t}\r\n  \t}\r\n\r\n  });\r\n\r\n  return Task;\r\n};\r\n```\r\n\r\n### model/result.js\r\n\r\n```javascript\r\nmodule.exports = function(sequelize, DataTypes) {\r\n\r\n  var Result = sequelize.define('Result', {\r\n    id: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true},\r\n    taskId: {type: DataTypes.INTEGER, allowNull: false, field: 'task_id', references: 'task', referencesKey: 'id'}\r\n }, {\r\n  \ttableName: 'result',\r\n  \ttimestamps: true,\r\n    classMethods: {\r\n      associate: function(models) {\r\n        Result.belongsTo(models.Task, {\r\n          foreignKey: 'task_id'\r\n        });\r\n      }\r\n    }\r\n  });\r\n\r\n  return Result;\r\n};\r\n```\r\n\r\n### test/db.test.js\r\n```javascript\r\nTask.findOrCreate({where: taskData}).then(function (task) {\r\n  task.getResults.should.be.a.Function;\r\n  task.addResult.should.be.a.Function;\r\n});\r\n```\r\n\r\nthe test result is `TypeError: Cannot read property 'should' of undefined`.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/74134859","html_url":"https://github.com/sequelize/sequelize/issues/3103#issuecomment-74134859","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/3103","id":74134859,"user":{"login":"mickhansen","id":699049,"avatar_url":"https://avatars.githubusercontent.com/u/699049?v=3","gravatar_id":"","url":"https://api.github.com/users/mickhansen","html_url":"https://github.com/mickhansen","followers_url":"https://api.github.com/users/mickhansen/followers","following_url":"https://api.github.com/users/mickhansen/following{/other_user}","gists_url":"https://api.github.com/users/mickhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/mickhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mickhansen/subscriptions","organizations_url":"https://api.github.com/users/mickhansen/orgs","repos_url":"https://api.github.com/users/mickhansen/repos","events_url":"https://api.github.com/users/mickhansen/events{/privacy}","received_events_url":"https://api.github.com/users/mickhansen/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T19:24:24Z","updated_at":"2015-02-12T19:24:24Z","body":"Looks like the names are correct, strange it's not working in practice.\r\nCan you try logging `Task.Instance.prototype`?"}}