Hey, i want To add relationships to my modèle.
But i have this error
Unexpected error: operator does not existe: integer = caractère varying
And there is my relationship
Address.hasOne(models.user, {
foreignKey: "uid",
targetKey: 'name'
});
I think it’s dont work because my primary key in User is a varchar…
So i dont know how To tell my primary key is a varchar and not a int.
(Sorry for my bad english…)
Express Version:4.16.3
Sequelize Version:5.15.1
louis
September 28, 2020, 1:02pm
2
Hey @Alexandre_TITEUX and welcome to our community!
Would you mind sharing your User model definition (models/user.js file)?
Thanks
Here
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const User = sequelize.define('user', {
uid: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
},
firstname: {
type: DataTypes.STRING,
allowNull: false,
},
lastname: {
type: DataTypes.STRING,
allowNull: false,
},
}, {
tableName: 'user',
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
User.associate = (models) => {
User.belongsTo(models.address, {
foreignKey: {
name: 'addressIdKey',
field: 'addressId',
},
as: 'address',
});
};
return User;
};
louis
September 29, 2020, 8:14am
4
@Alexandre_TITEUX , can you try to define your field as follow?
uid: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
},
It’s doesn’t work.
But I want to do a HasOne in my address entity
Address.hasOne(models.user, {
foreignKey: {
name: 'addressIdKey',
field: 'addressId',
},
as: 'user',
});
But when I do this config it’s written :
Unexpected error: column user.id does not exist
And then when I do this I have this error:
Unexpected error: operator does not exist: integer = character varying
My user.uid is a string.
user.addressId: Number
address.id: Number
And all my hasOne don’t work.
Hello @Alexandre_TITEUX , welcome to our community
I have been able to reproduce your issue, looks like hasOne relationships with custom primary key (other than id
) doesn’t work.
I’m digging a little bit more and I will keep you in touch.
Steve.
1 Like
Ok, thanks for you’re help !
Hello @Alexandre_TITEUX
We have identified the issue, and we are working for a fix. I can’t give you any ETA but you can downgrade forest-express-sequelize
to version 6.3.6 and it should work (keep me in touch if you encounter issues after having changed the version).
We will ping you as soon as the bug is fixed.
Sorry for the inconvenience, I hope this will help.
Steve.
Hello @Steve_Bunlon
Thanks for your help but when I downgrade forest-express-sequelize it still doesn’t work, I have the same Issue
Hi @Alexandre_TITEUX ,
Sadly, I’m not able to reproduce your issue using 6.3.6.
I’ll need some more infos on your setup:
Could you provide me your project name so I can dig into this ?
Which version of forest-express-sequelize
were you using before the downgrade ?
npm ls forest-express-sequelize
does return you 6.3.6 ?
You’re right @jeffladiray ,
I’m so sorry I didn’t downgrade well forest-express-sequelize and now it’s working better.
Thank you.
And when it’s will be fixed?
No problem.
The ticket is created, but I can’t really give you any ETA. I’ll link this thread to the ticket, so you’ll be informed once released.
Hello @Alexandre_TITEUX ,
We just released forest-express-sequelize
version 6.3.13
that will fix your issue. Can you test it on your side and validate that it works as expected?
Thanks
Thanks, it’s working now !