Skip to content
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

ER_DUP_FIELDNAME: Duplicate column name 'profileId' #450

Closed
sdinesh86 opened this issue Mar 24, 2020 · 17 comments
Closed

ER_DUP_FIELDNAME: Duplicate column name 'profileId' #450

sdinesh86 opened this issue Mar 24, 2020 · 17 comments

Comments

@sdinesh86
Copy link

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

@sdinesh86 sdinesh86 changed the title ER_DUP_FIELDNAME: Duplicate column name ER_DUP_FIELDNAME: Duplicate column name 'profileId' Mar 24, 2020
@michaelyali
Copy link
Member

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

@sdinesh86
Copy link
Author

I just tried with this setup
image

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

@michaelyali
Copy link
Member

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

@sdinesh86
Copy link
Author

I will share the relations

@sdinesh86
Copy link
Author

Post Entity

image

Comment Entity
image

image

@sdinesh86
Copy link
Author

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

@sdinesh86
Copy link
Author

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

image

@michaelyali
Copy link
Member

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

@sdinesh86
Copy link
Author

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

@sdinesh86
Copy link
Author

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,

@michaelyali
Copy link
Member

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

@sdinesh86
Copy link
Author

sorry didnt get you, can you elaborate

@csakbalint
Copy link

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

@csakbalint
Copy link

csakbalint commented Apr 23, 2020

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.

@michaelyali
Copy link
Member

fixed in v4.6.0

@sdinesh86
Copy link
Author

Thanks a lot, saved the day

@jongomes
Copy link

jongomes commented Jun 1, 2022

erro 5.0.0-alpha.3
work me
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants