question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alias for include models

See original GitHub issue

Hi, I want to use alias for include models. I have tried it with this: ModelA.hasMany(ModelB, {foreignKey: 'ABC'}); ModelB.belongsTo( ModelA, {as: 'XYZ' , foreignKey: 'ABC'}); But this does’t work. I have tried to specify “as” in include model array like: model: models.ModelB, required: false, as: 'Model_ALIAS' attributes: [ 'id', 'selector', [sequelize.fn('COUNT', sequelize.col('selector')), 'total_count'] ], group: ['id'], order: "total_count DESC"

But this throws an error that ModelB (Model_ALIAS) is not associated to ModelA. How can i define an alias to associated model so that all column prefix gets that alias like Model_ALIAS.id?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
mickhansencommented, Jun 1, 2016

We allow multiple associations between the same models.

3reactions
ariful-regfirecommented, Apr 9, 2019

Model B is associated to Model A using an alias. You must use the ‘as’ keyword to specify the alias within your include statement.

But I have added ‘as’ keyword to the include already. Can anyone help me with this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

sequelize select and include another table alias - Stack Overflow
As you have defined alias name in below code is building : City.hasMany(models.building,{as: 'building', foreignKey: 'cityId'}).
Read more >
Custom aliases - dbt Developer Hub
In combination with custom schemas, model aliasing is a powerful mechanism ... The alias config can be used to change the name of...
Read more >
Eager Loading - Sequelize
If an association is aliased (using the as option), you must specify this alias when including the model. Instead of passing the model...
Read more >
Which alias terms to include in fit model - JMP User Community
Which alias terms to include in fit model ... which are significant vary depending on which alias terms I include in the fit...
Read more >
Modeling | Alias Products 2022 - Autodesk Knowledge Network
Reference Manager additions. We've continued to add improvements and additions to reference data workflows. Support for group nodes. In 2022, we ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found