Context
Lets say I have two tables countries and users. In countries there are columns like id, name, code. code is a unique column and an alpha-2 of the country (UK, US, etc). users is linked to countries via code.
What is generated
In users model
countryCode: {
type: DataTypes.STRING(2),
allowNull: false,
references: {
model: 'countries',
key: 'code',
},
field: 'country_code',
},
In associations
users.belongsTo(countries, { as: 'countryCodeCountry', foreignKey: 'countryCode' });
countries.hasMany(users, { as: 'users', foreignKey: 'countryCode' });
With this associations, the Sequelize generate wrong query resulting in error of trying to compare character varying to bigint
What is expected to generate
users.belongsTo(countries, { as: 'countryCodeCountry', foreignKey: 'countryCode', targetKey: 'symbol' });
countries.hasMany(users, { as: 'users', foreignKey: 'countryCode' });
Am I missing configuration or I am doing it wrong?
Context
Lets say I have two tables
countriesandusers. Incountriesthere are columns likeid,name,code.codeis a unique column and an alpha-2 of the country (UK,US, etc).usersis linked tocountriesviacode.What is generated
In
usersmodelIn associations
With this associations, the Sequelize generate wrong query resulting in error of trying to compare character varying to bigint
What is expected to generate
Am I missing configuration or I am doing it wrong?