Crud: ER_DUP_FIELDNAME: Duplicate column name 'profileId'

Created on 24 Mar 2020  路  16Comments  路  Source: nestjsx/crud

First of all thanks everyone contributing to this awesome library.

I am having trouble joining nested relations, below is my use case

image

Any help would be appriciated

Thanks,
Dinesh

PRs open medium typeorm bug

All 16 comments

Hi, have you tried to add aliases in every join option?

I just tried with this setup
image

With this I am not getting the error, but I am not getting the profile object anywhere

that means that you have something wrong with defining relations in entities

I will share the relations

Post Entity

image

Comment Entity
image

image

I looked into the code a bit and found that, on using alias the relationMetadata is not found due to which the join is not happening
image

Please ignore the joinOptions argument in the getRelationMetadata method, thats something i was started playing around in order to dig into the issue

I logged the query, and noticed that an alias for column has been assigned to every other column except the profileId columns

image

Could you please confirm that you've added profileId as a column to every entity that has profile relation? If not, I think you should add it

Only user entity has a Profile relation.
I have the join column decorator on the relation so adding the profileId column throw DUP_KEY error while running
I tried removing the JoinColumn and adding a profileId column as well like below with no luck still the same error dup_fieldname
image

Ok I think I got it working finally 馃槍

Here is the summary of the whole thing

Select statement in the setJoin cases the relation to be included
image

As seen below

image

So i wrote a very hacky code to exclude the nested selects after the complete query has been built from createBuilder method
image

nest I also noticed getRelationMetaData method was not including the nested relations which are aliased, so again here is the quick hacky code i wrote to make it work

image

I tested this with against my usecase with alias's for now.
I some once can share their thoughts on the approach and if its on the right track then I will start writting some test cases and open a PR for the same.

Thanks,

Why don't you use required: false for left join relations?

sorry didnt get you, can you elaborate

Is there any update about this? It seems that joining previously aliased related entities is not working at all.

that means that you have something wrong with defining relations in entities

Or you cannot join aliased relations by the documentation:

Each key of join object must strongly match the name of the corresponding resource relation. If particular relation name is not present in this option, then user will not be able to get this relational objects in GET request.

fixed in v4.6.0

Thanks a lot, saved the day

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jbjhjm picture jbjhjm  路  4Comments

lafeuil picture lafeuil  路  5Comments

nikitammf picture nikitammf  路  3Comments

rainercedric23 picture rainercedric23  路  3Comments

terapepo picture terapepo  路  3Comments