简体   繁体   English

顺序添加关联

[英]Sequelize adding association

I'm trying to add association to my organization model but am having problems with the .add part of sequelize. 我正在尝试将关联添加到我的组织模型中,但是sequelize的.add部分存在问题。 I defined the association as such: 我将关联定义为:

models.organisation.hasMany(models.event, {
      foreignKey: 'organisationKey'
    });

And when an organization and an event has been created I tried to associate them through the following code: 创建组织和事件后,我尝试通过以下代码将它们关联:

organisation.addmodels.event(event);

I got this from the sequelize docs which says that you should do something like this: where I'm guessing that the "project" and "event" is supposed to be created objects and the "Project" is supposed to be the sequelize model. 我是从sequelize文档中获得的,该文档说您应该执行以下操作:我猜测应该在“项目”和“事件”中创建对象,而在“ Project”中将其作为sequelize模型。

project.addProject(project)

Any help would be much appreciated! 任何帮助将非常感激!

The problem was in the syntax which could be solved by storing the model in a variable as such: 问题在于语法,可以通过将模型存储在这样的变量中来解决:

var Event = models.event;
organisation.addEvent(event);

Not the cleanest solution but it works. 不是最干净的解决方案,但它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM