sequelize / sequelize/sequelize
fail if sourceKey for hasMany was not found
Open
Nobody has claimed this yet.
type: bug
- Dominant language
- TypeScript
- Stars
- 30.4k
- Forks
- 4.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 68
Description
What you are doing?
const hotelAttributeList = sequelize.define('hotelAttributeList', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true,
field: 'hotel_attribute_list_id'
},
eanHotelId: {
type: DataTypes.INTEGER(11),
allowNull: true,
field: 'ean_hotel_id'
}
},
{
tableName: 'hotel_attribute_list'
})
const hotelProperties = sequelize.define('hotelProperties', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true,
field: 'hotel_properties_id'
},
eanHotelId: {
type: DataTypes.STRING(10),
allowNull: false,
field: 'ean_hotel_id'
}
},
{
tableName: 'hotel_properties'
});
hotelProperties.hasMany(hotelAttributeList, {
sourceKey: 'eanHotelId',
foreignKey: 'eanHotelId'
});
What do you expect to happen?
I expect the column ean_hotel_id to join to ean_hotel_id between the tables
What is actually happening?
primary key hotel_properties_id is joining against ean_hotel_id.
Dialect: mysql
Sequelize version: 3.30.4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the hasMany association from the issue body with the MySQL dialect, then trace how Sequelize resolves sourceKey and foreignKey for this association. Done means the generated join uses hotel_properties.ean_hotel_id and hotel_attribute_list.ean_hotel_id rather than the primary key.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mysql, node.js
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100