• <bdo id='2Yvho'></bdo><ul id='2Yvho'></ul>
    1. <i id='2Yvho'><tr id='2Yvho'><dt id='2Yvho'><q id='2Yvho'><span id='2Yvho'><b id='2Yvho'><form id='2Yvho'><ins id='2Yvho'></ins><ul id='2Yvho'></ul><sub id='2Yvho'></sub></form><legend id='2Yvho'></legend><bdo id='2Yvho'><pre id='2Yvho'><center id='2Yvho'></center></pre></bdo></b><th id='2Yvho'></th></span></q></dt></tr></i><div id='2Yvho'><tfoot id='2Yvho'></tfoot><dl id='2Yvho'><fieldset id='2Yvho'></fieldset></dl></div>

    2. <tfoot id='2Yvho'></tfoot>

      <legend id='2Yvho'><style id='2Yvho'><dir id='2Yvho'><q id='2Yvho'></q></dir></style></legend>

      <small id='2Yvho'></small><noframes id='2Yvho'>

      sequelize Model.hasOne 错误:模型未关联到 ModelTwo

      sequelize Model.hasOne Error: Model is not associated to ModelTwo(sequelize Model.hasOne 错误:模型未关联到 ModelTwo)

            <bdo id='EqTcx'></bdo><ul id='EqTcx'></ul>

            <i id='EqTcx'><tr id='EqTcx'><dt id='EqTcx'><q id='EqTcx'><span id='EqTcx'><b id='EqTcx'><form id='EqTcx'><ins id='EqTcx'></ins><ul id='EqTcx'></ul><sub id='EqTcx'></sub></form><legend id='EqTcx'></legend><bdo id='EqTcx'><pre id='EqTcx'><center id='EqTcx'></center></pre></bdo></b><th id='EqTcx'></th></span></q></dt></tr></i><div id='EqTcx'><tfoot id='EqTcx'></tfoot><dl id='EqTcx'><fieldset id='EqTcx'></fieldset></dl></div>
            • <legend id='EqTcx'><style id='EqTcx'><dir id='EqTcx'><q id='EqTcx'></q></dir></style></legend>
              <tfoot id='EqTcx'></tfoot>

                <small id='EqTcx'></small><noframes id='EqTcx'>

                  <tbody id='EqTcx'></tbody>

              • 本文介绍了sequelize Model.hasOne 错误:模型未关联到 ModelTwo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我已将 sequelizejs 集成到我的 express 框架中.我配置了所有模型并尝试使用它构建我的第一个查询.

                I've integrated sequelizejs into my express framework. I got all the models configured and was trying to build my first query with it.

                我不断收到错误消息错误:模型未与 ModelTwo 关联!"

                I keep getting the error "Error: Model is not associated to ModelTwo!"

                app.get('/',function(req,res){
                 db.Member.findAll({include:[{model:db.MemberProfile,as:'Profile'}]})
                 .success(function(users){
                  if(users){
                   res.json(users);
                  }else{
                   res.send('no users');
                  }
                 });
                });
                

                //模型.js

                module.exports = function(sequelize,sql) {
                 return sequelize.define('Model', {
                  //attributes
                 });
                
                 Model.hasOne('ModelTwo',{foreignKey:'model_id'});
                
                };
                

                //model_two.js

                //model_two.js

                module.exports = function(sequelize,sql) {
                 return sequelize.define('ModelTwo', {
                  //attributes
                 });
                
                //no relationship defined. Tried ModelTwo.hasMany('Model',{foreignKey:'id'});
                //but it yields the same resulting error
                };
                

                关于可能出现什么问题的任何想法?我用的是最新版的sequelize 1.7.0-rc6.

                Any ideas as to what may be going wrong? I'm using the latest version of sequelize 1.7.0-rc6.

                推荐答案

                这其实是另一种情况,抛出同样的错误,

                This is actually another case which throws the same error,

                当我在包含模型时尝试使用 as 选项进行别名时遇到了同样的问题.只要您为默认名称起别名,这不会引发错误,但如果您尝试不同的名称,则会出错.

                I ran in to the same issue when I try to use as option for aliasing when including the model. This will not throw an error as long as you aliased the default name, but you'll get error if you try different name.

                解决办法,

                上面写的很清楚

                如果关联是别名(使用 as 选项),您必须指定包含模型时的此别名.

                If an association is aliased (using the as option), you must specify this alias when including the model.

                这意味着,反之亦然

                如果你想在包含模型时给模型起别名,它的关联必须是别名(使用 as 选项).

                If you want to alias a model when including, it's association must be aliased (using the as option).

                这篇关于sequelize Model.hasOne 错误:模型未关联到 ModelTwo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                • <i id='snt5A'><tr id='snt5A'><dt id='snt5A'><q id='snt5A'><span id='snt5A'><b id='snt5A'><form id='snt5A'><ins id='snt5A'></ins><ul id='snt5A'></ul><sub id='snt5A'></sub></form><legend id='snt5A'></legend><bdo id='snt5A'><pre id='snt5A'><center id='snt5A'></center></pre></bdo></b><th id='snt5A'></th></span></q></dt></tr></i><div id='snt5A'><tfoot id='snt5A'></tfoot><dl id='snt5A'><fieldset id='snt5A'></fieldset></dl></div>

                    • <bdo id='snt5A'></bdo><ul id='snt5A'></ul>

                    • <tfoot id='snt5A'></tfoot>

                        1. <legend id='snt5A'><style id='snt5A'><dir id='snt5A'><q id='snt5A'></q></dir></style></legend>

                            <tbody id='snt5A'></tbody>

                          <small id='snt5A'></small><noframes id='snt5A'>