Skip to content

[DoctrineBridge] indexBy could reference to association columns #38628

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

Merged
merged 2 commits into from
Nov 9, 2020

Conversation

juanmiguelbesada
Copy link
Contributor

Q A
Branch? 3.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #37982
License MIT
Doc PR -

This is my approach to solve #37982. It partials reverts @xabbuh PR #38604

This is my first Symfony contribution, so please, tell me if I need to do something more or something is wrong.

Also, this bug affects 4.x and 5.x versions. I think merging in this branches is done automatically. If not, please tell me.

Thanks you

$associationMapping = $subMetadata->getAssociationMapping($fieldName);

/** @var ClassMetadataInfo $subMetadata */
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we add some kind of check that the column name used here is in fact the join column?

@nicolas-grekas
Copy link
Member

Please check #38861 also.

@juanmiguelbesada
Copy link
Contributor Author

I will take a look

Copy link
Member

@jderusse jderusse left a comment

Choose a reason for hiding this comment

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

People at Doctrine says it could/shoud be a property (doctrine/orm#8018 (comment))
Which leads to issue in Symfony: #38861

Given this is not clear, I suggest to supports both cases:

  • IndexBy point to a property
  • IndexBy point to a column_name

@bwach
Copy link

bwach commented Oct 30, 2020

People at Doctrine says it could/shoud be a property (doctrine/orm#8018 (comment))
Which leads to issue in Symfony: #38861

Given this is not clear, I suggest to supports both cases:

* IndexBy point to a property

* IndexBy point to a column_name

This is also reflected in description for ClassMetadataInfo which we use here (depending on how you understand the whole paragraph)

https://github.com/doctrine/orm/blob/c1943624ab1260c629316bab104dc5130c060154/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L516

describing "indexBy" as:

Specification of a field on target-entity that is used to index the collection by.

So it should be one of the fields on the entity, not a column.
I guess the problem in the long run is that doctrine doesn't validate this, so you can type anything into the "indexBy" annotation and it will still work.

@xabbuh
Copy link
Member

xabbuh commented Nov 2, 2020

How does Doctrine behave for one or the other? Does it ignore the attribute? Does it try to map the column to a property or vice versa?

@juanmiguelbesada juanmiguelbesada force-pushed the issue-37982 branch 2 times, most recently from 6b58fa4 to a0b6778 Compare November 5, 2020 06:56
@juanmiguelbesada
Copy link
Contributor Author

PR updated fixing #38861 (I hope) and adding tests

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

LGTM

@carsonbot carsonbot changed the title [DoctrineBridge] indexBy could reference to association columns [DoctrineBridge] indexBy could reference to association columns Nov 9, 2020
@nicolas-grekas
Copy link
Member

Thank you @juanmiguelbesada.

@nicolas-grekas nicolas-grekas merged commit 6724ca7 into symfony:3.4 Nov 9, 2020
@fabpot fabpot mentioned this pull request Nov 10, 2020
@fabpot fabpot mentioned this pull request Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants