Skip to content

[DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity #39667

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 1 commit into from
Jan 15, 2021

Conversation

victormacko
Copy link
Contributor

@victormacko victormacko commented Dec 31, 2020

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets none
License MIT
Doc PR bug-fix only

In Symfony 4.4.17 (I think), using ManyToMany in doctrine, along with indexBy="person_id" (in the related entity, which has a property of "id" (which in-turn uses the db column "person_id" worked as expected. When upgrading to Symfony 5.2.1, this stops working.

This change continues on from issue #37982 to fix a further edge case.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.x branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@victormacko victormacko changed the title Take into account that indexBy="person_id" could be a db column name,… [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name,… Dec 31, 2020
@victormacko victormacko changed the title [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name,… [DoctrineBridge][DoctrineExtractor] Take into account that indexBy="person_id" could be a db column name,… Dec 31, 2020
@carsonbot carsonbot changed the title [DoctrineBridge][DoctrineExtractor] Take into account that indexBy="person_id" could be a db column name,… [DoctrineBridge] [DoctrineExtractor] Take into account that indexBy="person_id" could be a db column name,… Dec 31, 2020
@OskarStark
Copy link
Contributor

Could you add a testcase?

@victormacko
Copy link
Contributor Author

@OskarStark Sure -- just noticed I had missed that part, but got distracted with new years stuff! ... will try and get one up shortly.

@OskarStark
Copy link
Contributor

Thank you 😊

@nicolas-grekas nicolas-grekas changed the title [DoctrineBridge] [DoctrineExtractor] Take into account that indexBy="person_id" could be a db column name,… [DoctrineBridge] [DoctrineExtractor] Take into account that indexBy="person_id" could be a db column name, for a referenced entity Jan 3, 2021
@nicolas-grekas nicolas-grekas added this to the 5.2 milestone Jan 3, 2021
@nicolas-grekas nicolas-grekas changed the base branch from 5.x to 5.2 January 4, 2021 18:24
@nicolas-grekas nicolas-grekas changed the base branch from 5.2 to 5.x January 4, 2021 18:24
@nicolas-grekas nicolas-grekas changed the title [DoctrineBridge] [DoctrineExtractor] Take into account that indexBy="person_id" could be a db column name, for a referenced entity [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity Jan 4, 2021
@nicolas-grekas nicolas-grekas changed the base branch from 5.x to 5.2 January 4, 2021 18:27
@nicolas-grekas nicolas-grekas force-pushed the doctrine-bridge-property-extractor branch from c877884 to a3fa8e1 Compare January 4, 2021 18:27
@nicolas-grekas nicolas-grekas modified the milestones: 5.2, 4.4 Jan 5, 2021
@nicolas-grekas nicolas-grekas changed the base branch from 5.2 to 4.4 January 5, 2021 18:43
@nicolas-grekas nicolas-grekas requested a review from lyrixx as a code owner January 5, 2021 18:43
@nicolas-grekas nicolas-grekas force-pushed the doctrine-bridge-property-extractor branch from a3fa8e1 to bd3fe22 Compare January 5, 2021 18:43
@nicolas-grekas
Copy link
Member

Now rebased for 4.4

@wouterj wouterj removed their request for review January 12, 2021 12:45
@fabpot
Copy link
Member

fabpot commented Jan 13, 2021

@victormacko Can you have a look at the tests as they seem to be broken by your changes.

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.

once tests are fixed

@victormacko
Copy link
Contributor Author

victormacko commented Jan 15, 2021

Done @fabpot .. let me know if there's anything I can do to help with the other failing tests - one is a class-ref issue, and another due to commits (both of which i'm not sure about how to assist with)

@fabpot
Copy link
Member

fabpot commented Jan 15, 2021

@victormacko Something went wrong here as there are many unrelated changes. Can you rebase on the current 4.4 branch?

@xabbuh xabbuh force-pushed the doctrine-bridge-property-extractor branch 2 times, most recently from f3610f3 to 1e2367d Compare January 15, 2021 08:23
@xabbuh xabbuh force-pushed the doctrine-bridge-property-extractor branch from 1e2367d to 472eab1 Compare January 15, 2021 08:23
@xabbuh
Copy link
Member

xabbuh commented Jan 15, 2021

Thank you @victormacko.

@xabbuh xabbuh merged commit 8076c2f into symfony:4.4 Jan 15, 2021
@victormacko
Copy link
Contributor Author

Nps, thanks @xabbuh -- not sure what happened either, but appreciate your help :)

@victormacko victormacko deleted the doctrine-bridge-property-extractor branch January 15, 2021 11:06
This was referenced Jan 27, 2021
@da-anda
Copy link

da-anda commented Jun 29, 2022

unfortunately this issue still persists in 5.4.10 if indexBy is using a subproperty of a relation n:1 property of the relation. Symfony/Doctrine itself is working fine doing this and correctly indexing the relations, but the mentioned exception is thrown when resolving validations.

Example:

class Article {
    /**
     * @var ArticleAttribute[]
     * @ORM\OneToMany(targetEntity=ArticleAttribute::class, mappedBy="article", cascade={"all"}, indexBy="attribute.name")
     */
    private $attributes;
}

class ArticleAttribute {
    /**
     * @var Attribute
     * @ORM\ManyToOne(targetEntity=Attribute::class)
     * @ORM\JoinColumn(nullable=false)
     */
    private $attribute;
}

class Attribute {
    /**
     * @var string
     * @ORM\Column(type="string", length=30, unique=true)
     */
    private $name;
}

any ideas?

@stof
Copy link
Member

stof commented Jun 29, 2022

@da-anda please open a new ticket instead of commenting on a PR merged more than 1 year ago. Otherwise, the only way to find back the discussion is through notifications (as nobody goes checking old merged PRs for new comments), and not everyone gets notifications for all new comments.
and please provide full details to help debugging.

@da-anda
Copy link

da-anda commented Jun 29, 2022

done

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.

10 participants