This kind of issue usually occur when we try to compare mismatched data types. You cannot compare an integer with a varchar. PostgreSQL is strict and does not do any magic typecasting for you. I’m guessing SQLServer does typecasting automagically (which is a bad thing).
The above code throws operator does not exist: integer = character varying exception, because we are trying to compare integer with string. To fix this issue change as follows
<code>const phone = "9998886660"; //this will fix the issue
UserModel.count({
where: {
phone: phone
}
});</code>
When we want to fetch the user who has posted the notice, we will use the following code,
<code>const query ["include"] = [{model: UserModel}]
// query can include all some conditions required, this is out of scope of this tutorial, for the same you can check out this
const notices = await NoticeModel.findAll(query);</code>
Once we add the above changes, both noticedBy and noticeTo will be filled. (Observe we have not kept the alias name same, we have changed them slightly).
Possible errors
uncaughtException: Naming collision between attribute ‘noticeTo’ and association ‘noticeTo’ on model notices. To remedy this, change either foreignKey or as in your association definition\nError: Naming collision between attribute ‘noticeTo’ and association ‘noticeTo’ on model notices
What does the above error mean?
It says that we have given same names to the attribute i.e foreign key and alias. We get this with the following code,