Database Error: eager loaded column of the junction table within a M:N relationship doesn't exist #17203
Unanswered
razvan286
asked this question in
Help & Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been spending a couple of days trying to find the solution for this but no luck still. The following issue doesn't happen on
localhost
, it only happens in a Docker container (I always use thebuild --no-cache
command).I have three models in place
Activity
,Item
, andLabel
.Self-referential One-to-Many relationship in Label
with an alias assubLabels
.M:N relationship between Activity and Label
M:N relationship between Item and Label
I also have an explicit junction model named
LabelAssociations
.The
Activity
model:Need to mention that I explicitly specify the
@HasMany
LabelAssociations
relationship to be able to query the junction table by theactivityId
as you can see below.The
Item
model:The
Label
model:The
LabelAssociations
model:I have explicitly created a model for the junction table to be able to create the foreign keys:
activityId
, anditemId
. I have otherM:N
relationships in my application where it didn't require to explicitly create the junction model and everything works properly there.I will exemplify the errors by only referring to the
Activity
model as theItem
queries are mostly similar.After a lot of trials I got to the following query by having to explicitly specify the attributes that I want to be loaded for the
Label
eager loadings, otherwise other attributes would've been loaded:With the current model definitions and the just mentioned query, when this query is performed in the Docker container I get the following error:
ERROR: column labels->LabelAssociations.activityId does not exist
The complete query:
I need to mentioned that I can get rid of the error from above by updating the relationship specified in the
Activity
model from:to:
But with this change I then run into other issues where queries on the junction table fail such as:
The above query was failing because instead of
activityId
was trying to add to theitemId
column a null value as it wasn't specified. It seemed that it was only able to verify theitemId
foreign key and theactivityId
was somehow missing.I have previously seen some other opened issues similar to mine. However, some of them were happening because of the
LIMIT
specified in the query which is not the case here.Any help would be appreciated. Thank you in advance.
Dialect: postgres
Database version: 15
Sequelize version: 6.25.3
Sequelize-typescript version: 2.1.6
EDIT:
I think I was assessing the error from a bad point of view. The actual error is that sequelize doesn't recognize the
activityId
foreign key column in theLabelAssociations
model.Beta Was this translation helpful? Give feedback.
All reactions