-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicate column names for associations and misleading documentation #9328
Comments
const Basket = sequelize.define('Basket', { .... }); Well its up for discussion, @sequelize/orm what do you suggest here? Enforce proper camel case key even if model name is upper cased? I think many user prefer PascalCase naming for model, but camel case for attributes name. It make sense to keep attributes camelCased not PascalCased |
I think the implication is that the foreign key column should assume that it is in camelCase even if the model is in PascalCase, which I think is a logical assumption. |
Yeah...not the best bug to try and sort out. I guess I will just be explicit in all model associations |
Same issue here, I was getting the |
still an issue |
i just ran into this duplicate column bug after updating from sequelize |
@broox thank you for your help, I just downgraded my Sequelize version to actually fix this issue. |
thank u , i have this issue , it help me |
I tried to downgrade to 4.44.4, currently on 5.21.3, also tried 6.3.3, I'm still having the same issue for all three versions |
I am using version |
Every time I ran into this kind of problem, either I use one of these 2 options into the query config:
Somehow, most of the time it ends up working. |
thanks!! |
Summary
We ran into an issue recently where
sequelize
generates queries with duplicate column names that cause mysql to errors in subqueries.A similar issue documented here: #3035 allowed us to fix the issue by specifying the
foreignKey
.However this appears to be in conflict with the documentation which suggests that
foreignKey
iscamelCase
by defaultIt seems like
sequelize
has mismatched casing assumptions: association definitions assumecamelCase
while the query builder assumesUpperCamelCase
Longer explanation
We have three models,
Basket
,Apple
,Farmer
with associations as defined below:If we
findAll
It generates the following query. (note that
farmerId
is duplicated)If we instead want only 10
Baskets
, plus anyApples
in eachBasket
:It generates the following query with a subquery
Our duplicated columns are now in a subquery. When this query is run in mysql, it throws an error!
We can fix this by specifying the foreign key on our relationships:
However, the documentation suggests that
foreignKey
should already becamelCase
by default. It's not super clear to me why the query builder would assumeUpperCamelCase
. This seems like a bug.Info
Dialect: mysql, (generates the same queries for sqlite, but doesn't cause an error)
Dialect version: default?
Database version:
mysqld Ver 5.7.21 for osx10.12 on x86_64 (Homebrew)
Sequelize version:
4.17.0
and5.0.0-beta.3
The text was updated successfully, but these errors were encountered: