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

[GH-8043] Make IdentityFunction handle primary keys when they are part of an association #8288

Closed
wants to merge 1 commit into from

Conversation

MatTheCat
Copy link
Contributor

Fix #8043

When primary keys are part of an association they won’t be found in fieldMappings but in associationMappings so I refactored IdentityFunction to handle this case.

I’m not completely sure about the logic (especially the reset which I copied from line 61) but it worked for every case I thought of.

@drupol
Copy link

drupol commented Dec 2, 2020

Any news on this?

if (isset($targetEntity->fieldMappings[$this->fieldMapping])) {
$columnName = $targetEntity->fieldMappings[$this->fieldMapping]['columnName'];
} elseif (isset($targetEntity->associationMappings[$this->fieldMapping])) {
$columnName = reset($targetEntity->associationMappings[$this->fieldMapping]['joinColumns'])['name'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think reset() is here because we don't support IDENTITY with composite keys?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is the reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case could we throw an exception if there are more than one key?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, not sure why it wasn't done like that in the first place. Right now, it will only return the value of the first part of the composite key, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm from https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/dql-doctrine-query-language.html#:~:text=the%20IDENTITY()%20DQL I read

the IDENTITY() DQL function also works for composite primary keys

So there must be another reason 🤔

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should docs be added?

@SenseException
Copy link
Member

The bottom of https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/dql-doctrine-query-language.html#dql-select-examples shows some addition for every version change. This can be extended for this PR.

@MatTheCat MatTheCat changed the base branch from 2.7 to 2.8.x March 16, 2021 09:42
@MatTheCat
Copy link
Contributor Author

MatTheCat commented Mar 16, 2021

Hi everyone I’m back 👋

I changed the target branch to 2.8.x and added a test. Is everything alright?

@MatTheCat
Copy link
Contributor Author

MatTheCat commented Mar 16, 2021

@SenseException I feel like my PR is a bugfix so I’m not sure if I should add an example in the documentation?

@drupol
Copy link

drupol commented Mar 16, 2021

@SenseException I feel like my PR is a bugfix so I’m not sure if I should add an example in the documentation?

Bugfix or not, I think an example always worth :)

@MatTheCat
Copy link
Contributor Author

The documentation already has an example for

The IDENTITY() DQL function also works for composite primary keys

Should I add even if they’re part of an association? Don’t really know what to add 🤔

@SenseException
Copy link
Member

An addition that IdentityFunction can handle primary keys now would be sufficient.

@MatTheCat
Copy link
Contributor Author

@SenseException this PR allows IDENTITY to handle composite primary keys which also are foreign keys. From the documentation I expected this to work as it says

The IDENTITY() DQL function also works for composite primary keys

Now that it really works what could be to add?

@MatTheCat MatTheCat changed the title Make IdentityFunction handle primary keys when they are part of an association [GH-8043] Make IdentityFunction handle primary keys when they are part of an association Mar 19, 2021
@MatTheCat
Copy link
Contributor Author

@greg0ire I added a test and rebased

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

Successfully merging this pull request may close these issues.

Make IDENTITY function work with joined columns
4 participants