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

InverseJoinColumn use statement omitted when migrating Doctrine entity from annotations to attributes #7528

Closed
greg0ire opened this issue Oct 5, 2022 · 4 comments · Fixed by rectorphp/rector-src#2989
Labels

Comments

@greg0ire
Copy link
Contributor

greg0ire commented Oct 5, 2022

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.org/demo/fb5d815a-c5fb-457f-939c-16403065fd67

<?php


use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\Table;


/**
 * @Entity
 * @Table(name="lemma")
 */
class Lemma
{
    public const CLASS_NAME = self::class;

    /**
     * @Id
     * @Column(type="integer", name="lemma_id")
     * @GeneratedValue(strategy="AUTO")
     */
    private int $id;


    /** @ManyToMany(targetEntity="Type", mappedBy="lemmas", cascade={"persist"}) */
    private Collection $types;

    public function __construct()
    {
        $this->types = new ArrayCollection();
    }
}

/**
 * @Entity
 * @Table(name="type")
 */
class Type
{
    public const CLASS_NAME = self::class;

    /**
     * @Id
     * @Column(type="integer", name="type_id")
     * @GeneratedValue(strategy="AUTO")
     */
    private int $id;

    
    /**
     * @ManyToMany(targetEntity="Lemma")
     * @JoinTable(name="lemma_type",
     *      joinColumns={@JoinColumn(name="type_id", referencedColumnName="type_id")},
     *      inverseJoinColumns={@JoinColumn(name="lemma_id", referencedColumnName="lemma_id")}
     * )
     */
    private Collection $lemmas;

    public function __construct()
    {
        $this->lemmas = new ArrayCollection();
    }
}

Responsible rules

  • AnnotationToAttributeRector

  • NestedAnnotationToAttributeRector

Expected Behavior

Rector should do what it did AND add a use statement for InverseJoinColumn

@greg0ire greg0ire added the bug label Oct 5, 2022
@greg0ire greg0ire changed the title InverseJoinColumn use statement not adding wheh migrating Doctrine entity from annotations to attributes InverseJoinColumn use statement omitted when migrating Doctrine entity from annotations to attributes Oct 5, 2022
greg0ire added a commit to greg0ire/doctrine-orm that referenced this issue Oct 8, 2022
greg0ire added a commit to greg0ire/doctrine-orm that referenced this issue Oct 8, 2022
greg0ire added a commit to greg0ire/doctrine-orm that referenced this issue Oct 8, 2022
greg0ire added a commit to greg0ire/doctrine-orm that referenced this issue Oct 9, 2022
@TomasVotruba
Copy link
Member

TomasVotruba commented Oct 13, 2022

Thank you for your report and demo link!

Could you send a minimalistic failing test case in a pull-request, so we have it covered in Rector?
The responsible rule is NestedAnnotationToAttributeRector

@greg0ire
Copy link
Contributor Author

Will try that in the coming days!

@TomasVotruba
Copy link
Member

TomasVotruba commented Oct 13, 2022

Thanks. This property will be enough:

/**
     * @JoinTable(name="lemma_type",
     *      inverseJoinColumns={@JoinColumn(name="lemma_id", referencedColumnName="lemma_id")}
     * )
     */
    private Collection $lemmas;

greg0ire added a commit to greg0ire/rector-src that referenced this issue Oct 15, 2022
greg0ire added a commit to greg0ire/rector-src that referenced this issue Oct 15, 2022
@greg0ire
Copy link
Contributor Author

Done in rectorphp/rector-src#2987 🙂

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

Successfully merging a pull request may close this issue.

2 participants