Alias for include models
See original GitHub issueHi,
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:
- Created 7 years ago
- Comments:12 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We allow multiple associations between the same models.
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?