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

        <tfoot id='N3C8j'></tfoot>

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

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

        建立关联时,哪些方法/mixins sequelize 添加到模型中?

        What methods/mixins sequelize adds to the models when an association is made?(建立关联时,哪些方法/mixins sequelize 添加到模型中?)

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

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

              2. <small id='xd2O0'></small><noframes id='xd2O0'>

                  <bdo id='xd2O0'></bdo><ul id='xd2O0'></ul>
                  本文介绍了建立关联时,哪些方法/mixins sequelize 添加到模型中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在浏览

                  要了解此表的含义,请回想在该文档页面的开头,它说在下面的 API 参考中,将关联的名称添加到方法中".最令人困惑的部分是,何时应添加名称的单数版本以及何时应添加复数版本并不清楚.但是,尽管文档没有说明这一点,但我向您保证,您可以使用常识来猜测.如果您认为这两个版本都有意义(例如,对于 add),您会惊讶于实际上两个版本都可用.因此,从上表我们可以得出结论:

                  • 添加到 Person 模型实例的方法:

                    • addHypothesis()
                    • addHypotheses()
                    • countHypotheses()
                    • createHypothesis()
                    • getHypotheses()
                    • hasHypothesis()
                    • hasHypotheses()
                    • removeHypothesis()
                    • removeHypotheses()
                    • setHypotheses()
                  • 添加到假设模型实例的方法:

                    • addPerson()
                    • addPeople()
                    • countPeople()
                    • createPerson()
                    • getPeople()
                    • hasPerson()
                    • hasPeople()
                    • removePerson()
                    • removePeople()
                    • setPeople()

                  另一种毫无疑问地弄清楚这一点的方法是检查 Sequelize 源代码本身,即 这里,我们可以在这里找到:

                  this.accessors = {得到:得到"+复数,设置:'set' + 复数,addMultiple: 'add' + 复数,添加:'添加'+单数,创建:创建"+单数,删除:删除"+ 单数,removeMultiple: 'remove' + 复数,hasSingle: '有' + 单数,hasAll: '有' + 复数,计数:'计数'+复数};

                  注意:虽然看起来有悖常理,但实际上上述两种方法 addPerson()addPeople() 都使用相同的参数,可以是单个值或数组.换句话说,源代码中的addaddMultiple方法实际上是相同的,到底.这同样适用于 remove()removeMultiple(),以及 hasSingle()hasAll().

                  希望您现在可以理解 Sequelize 文档对这些表格的真正含义.

                  如果您喜欢直接查看源代码,类似于我上面显示的内容,这些是其他类型关联的相关行:

                  • 属于:这里

                    this.accessors = {得到:得到"+单数,设置:设置"+单数,创建:创建"+ 单数};

                  • HasOne:这里

                    this.accessors = {得到:得到"+单数,设置:设置"+单数,创建:创建"+ 单数};

                  • HasMany:这里

                    this.accessors = {得到:得到"+复数,设置:'set' + 复数,addMultiple: 'add' + 复数,添加:'添加'+单数,创建:创建"+单数,删除:删除"+ 单数,removeMultiple: 'remove' + 复数,hasSingle: '有' + 单数,hasAll: '有' + 复数,计数:'计数'+复数};

                  While going through the sequelize docs, more specifically the documentations about associations, I see that the guide casually shows the reader methods such as setTasks(), addTask(), setProject(), that seem to be automatically created by sequelize for all model instances with respect to the created associations.

                  I couldn't find detailed information on what methods are available, and whether they are created with the singular version or plural version (since there is both setTasks() and setProject(), for example), and what exactly are the parameters they expect, and such. The docs apparently just casually mention them inside the examples...

                  So, what methods/mixins sequelize adds to the models when an association is made? And what are the parameters and return values, i.e. what's the documentation for those methods? Or, at least, where can I find them?

                  解决方案

                  The documentation about associations you linked, although hosted in an address called docs.sequelize.js, isn't the real sequelize docs (as in fully covered docs with all details that a good documentation usually provides). That is more like a tutorial / guide for starters.

                  The real sequelize docs are found by clicking on the "Reference" link available in the side menu of the links you mentioned (and it took me quite a while to find that - it doesn't even look like a clickable thing IMO).

                  The parts you're interested here are these:

                  • Sequelize docs for BelongsTo type of associations: here
                  • Sequelize docs for BelongsToMany type of associations: here
                  • Sequelize docs for HasMany type of associations: here
                  • Sequelize docs for HasOne type of associations: here

                  Understanding the docs

                  Since the docs linked above can be very confusing, here is an explanation to assist you to understand the docs.

                  Let's assume, for example, that we have a belongs to many association between Person and Hypothesis. Note that their plural forms, People and Hypotheses, are automatically inferred by Sequelize. This magic is done under the hood by the awesome library called inflection - see How do plurals work in Sequelize? for more details.

                  // Assuming that the models Person, Hypothesis and Person_Hypothesis are already defined
                  Person.belongsToMany(Hypothesis, { through: Person_Hypothesis });
                  Hypothesis.belongsToMany(Person, { through: Person_Hypothesis });
                  

                  And we want to use the Sequelize docs for BelongsToMany type of associations to learn what methods were automatically added to instances of the Person and Hypothesis models. There, we can find the following table:

                  To understand what this table means, recall that in the beginning of that page of the docs it says that "In the API reference below, add the name of the association to the method". The most confusing part of this is that it's not so clear when you should add the singular version of the name and when you should add the plural version. But although the docs do not make this clear, I assure you that you can just use common sense to guess. And if you think both versions could make sense (for example, for add), be surprised that actually both versions are available. Therefore, from the table above, we can conclude:

                  • Methods added to instances of Person models:

                    • addHypothesis()
                    • addHypotheses()
                    • countHypotheses()
                    • createHypothesis()
                    • getHypotheses()
                    • hasHypothesis()
                    • hasHypotheses()
                    • removeHypothesis()
                    • removeHypotheses()
                    • setHypotheses()
                  • Methods added to instances of Hypothesis models:

                    • addPerson()
                    • addPeople()
                    • countPeople()
                    • createPerson()
                    • getPeople()
                    • hasPerson()
                    • hasPeople()
                    • removePerson()
                    • removePeople()
                    • setPeople()

                  Another way to figure this out without room for doubt is by checking the Sequelize source code itself, namely here, where we can find:

                  this.accessors = {
                      get: 'get' + plural,
                      set: 'set' + plural,
                      addMultiple: 'add' + plural,
                      add: 'add' + singular,
                      create: 'create' + singular,
                      remove: 'remove' + singular,
                      removeMultiple: 'remove' + plural,
                      hasSingle: 'has' + singular,
                      hasAll: 'has' + plural,
                      count: 'count' + plural
                  };
                  

                  Note: although it might seem counter-intuitive, in fact both methods addPerson() and addPeople() mentioned above work with the same parameters, which can be either a single value or an array. In other words, the methods add and addMultiple from the source code are actually the same, in the end. The same applies to remove() and removeMultiple(), and hasSingle() and hasAll().

                  Hopefully with this you can now understand what the Sequelize docs really mean with those tables.

                  If you prefer to check the source code directly, analogously to what I showed above, these are the relevant lines for the other kinds of associations:

                  • BelongsTo: here

                    this.accessors = {
                        get: 'get' + singular,
                        set: 'set' + singular,
                        create: 'create' + singular
                    };
                    

                  • HasOne: here

                    this.accessors = {
                        get: 'get' + singular,
                        set: 'set' + singular,
                        create: 'create' + singular
                    };
                    

                  • HasMany: here

                    this.accessors = {
                        get: 'get' + plural,
                        set: 'set' + plural,
                        addMultiple: 'add' + plural,
                        add: 'add' + singular,
                        create: 'create' + singular,
                        remove: 'remove' + singular,
                        removeMultiple: 'remove' + plural,
                        hasSingle: 'has' + singular,
                        hasAll: 'has' + plural,
                        count: 'count' + plural
                    };
                    

                  这篇关于建立关联时,哪些方法/mixins sequelize 添加到模型中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='1Zhec'><tr id='1Zhec'><dt id='1Zhec'><q id='1Zhec'><span id='1Zhec'><b id='1Zhec'><form id='1Zhec'><ins id='1Zhec'></ins><ul id='1Zhec'></ul><sub id='1Zhec'></sub></form><legend id='1Zhec'></legend><bdo id='1Zhec'><pre id='1Zhec'><center id='1Zhec'></center></pre></bdo></b><th id='1Zhec'></th></span></q></dt></tr></i><div id='1Zhec'><tfoot id='1Zhec'></tfoot><dl id='1Zhec'><fieldset id='1Zhec'></fieldset></dl></div>

                    <bdo id='1Zhec'></bdo><ul id='1Zhec'></ul>

                      <legend id='1Zhec'><style id='1Zhec'><dir id='1Zhec'><q id='1Zhec'></q></dir></style></legend>
                      <tfoot id='1Zhec'></tfoot>

                          <small id='1Zhec'></small><noframes id='1Zhec'>

                              <tbody id='1Zhec'></tbody>