Hi,
I have these two tables that are linked by a foreign key with a has_many relationship. Following are the models that I have implemented:
- Handlers:
const Handlers = (sequelize: any, DataTypes: any) => {
const Model = sequelize.define(
'handlers',
{
...
},
{
tableName: 'Handlers'
}
);
Model.associate = (models: any) => {
Model.hasMany(models.missions, {
foreignKey: {
name: 'handlerIdKey',
field: 'handlerId'
},
as: 'handlerMissions'
});
};
return Model;
};
- Missions:
const Missions = (sequelize: any, DataTypes: any) => {
const Model = sequelize.define(
'missions',
{
...
},
{
tableName: 'Missions'
}
);
Model.associate = (models: any) => {
Model.belongsTo(models.handlers, {
foreignKey: {
name: 'handlerIdKey',
field: 'handlerId'
},
as: 'handler'
});
};
return Model;
};
Smart View:
component.js
...
missionList: Ember.computed(
'currentRecord.forest-handlerMissions.@each',
function () {
return this.get('currentRecord.forest-handlerMissions').map(
function (mission) {
return mission;
}
);
}
),
actions: {
selectRecord: function (record) {
this.set('currentRecord', record);
}
}
...
template.hbs
// snippet 1
{{#each records as |record|}}
<a href="#" {{action "selectRecord" record}}>
<h4>{{record.forest-handlerMissions.length}}</h4>
</a>
{{/each}}
// snippet 2
{{#each missionList as |mission|}}
...
{{/each}}
Expected behavior
Snippet 1 should display the number of mission a handler has.
Snippet 2 should display the current handler’s missions
Actual behavior
The maximum number that appears is 10.
The maximum missions that appears are 10.
- Package Version: forest-express-sequelize 6.3.11
- Express Version: 4.17.1
- Sequelize Version: 5.8.9
- Database Dialect: postgres
- Database Version: 12
- Project Name: Kokoon