Association not escaping fieldname #5201

Closed
opened 2026-01-22 15:01:26 +01:00 by admin · 10 comments
Owner

Originally created by @michsk on GitHub (Jul 22, 2016).

Originally assigned to: @ostrolucky on GitHub.

class Option
{
    /**
     * @var int
     * @ORM\Column(name="`group`", type="smallint")
     */
    private $group;

    /**
     * @var Collection
     * @ORM\ManyToMany(targetEntity="Acme\Domain\Entity\Option\Option", inversedBy="dependingOptions")
     * @ORM\JoinTable(
     *     name="acme_opties_relaties",
     *     joinColumns={@ORM\JoinColumn(name="id_a", referencedColumnName="id")},
     *     inverseJoinColumns={@ORM\JoinColumn(name="id_b", referencedColumnName="id")}
     * )
     */
    private $requiredOptions;

    /**
     * @var Collection
     * @ORM\ManyToMany(targetEntity="Acme\Domain\Entity\Option\Option", mappedBy="requiredOptions")
     */
    private $dependingOptions;

    /**
     * @param Relation $r
     * @return Criteria
     */
    private function getRelationCriteria(Relation $relation): Criteria
    {
        return Criteria::create()->where(
            Criteria::expr()->eq('soort', $relation->getValue())
        );
    }

    public function getRequiredOptions()
    {
        return $this->requiredOptions->matching($this->getRelationCriteria(Relation::get(Relation::DEPEND)));
    }
}

Now just loading a Option, everything is fine. But when calling Option::getRequiredOptions() the group field name is not escaped.

Originally created by @michsk on GitHub (Jul 22, 2016). Originally assigned to: @ostrolucky on GitHub. ``` php class Option { /** * @var int * @ORM\Column(name="`group`", type="smallint") */ private $group; /** * @var Collection * @ORM\ManyToMany(targetEntity="Acme\Domain\Entity\Option\Option", inversedBy="dependingOptions") * @ORM\JoinTable( * name="acme_opties_relaties", * joinColumns={@ORM\JoinColumn(name="id_a", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="id_b", referencedColumnName="id")} * ) */ private $requiredOptions; /** * @var Collection * @ORM\ManyToMany(targetEntity="Acme\Domain\Entity\Option\Option", mappedBy="requiredOptions") */ private $dependingOptions; /** * @param Relation $r * @return Criteria */ private function getRelationCriteria(Relation $relation): Criteria { return Criteria::create()->where( Criteria::expr()->eq('soort', $relation->getValue()) ); } public function getRequiredOptions() { return $this->requiredOptions->matching($this->getRelationCriteria(Relation::get(Relation::DEPEND))); } } ``` Now just loading a `Option`, everything is fine. But when calling `Option::getRequiredOptions()` the `group` field name is not escaped.
admin added the BugMissing Tests labels 2026-01-22 15:01:26 +01:00
admin closed this issue 2026-01-22 15:01:27 +01:00
Author
Owner

@michsk commented on GitHub (Jul 22, 2016):

Tough when changing the annotation to:

    /**
     * @var Group
     * @ORM\Column(name="`notexitingfieldname`", type="smallint")
     */
    private $group;

i get a SQL error that the field can not be found, tough in the error i see the field is not escaped.

@michsk commented on GitHub (Jul 22, 2016): Tough when changing the annotation to: ``` php /** * @var Group * @ORM\Column(name="`notexitingfieldname`", type="smallint") */ private $group; ``` i get a SQL error that the field can not be found, tough in the error i see the field is not escaped.
Author
Owner

@Deltachaos commented on GitHub (Jul 22, 2016):

@Michal-sk are you able to write a test that reproduces this issue?

@Deltachaos commented on GitHub (Jul 22, 2016): @Michal-sk are you able to write a test that reproduces this issue?
Author
Owner

@michsk commented on GitHub (Jul 22, 2016):

sure

@michsk commented on GitHub (Jul 22, 2016): sure
Author
Owner

@Deltachaos commented on GitHub (Jul 22, 2016):

@Michal-sk would be greae if you create a PR that contains this test. A fix could then be build against the test.

@Deltachaos commented on GitHub (Jul 22, 2016): @Michal-sk would be greae if you create a PR that contains this test. A fix could then be build against the test.
Author
Owner

@michsk commented on GitHub (Jul 22, 2016):

Ok, maybe you could tell more about the idea / structure behind the tests? I am a bit overwhelmed and not sure where to start when looking in the tests folder. Do i place the test in M:\files\dev\products\kp\doctrine2\tests\Doctrine\Tests\ORM\Functional\Ticket?

@michsk commented on GitHub (Jul 22, 2016): Ok, maybe you could tell more about the idea / structure behind the tests? I am a bit overwhelmed and not sure where to start when looking in the tests folder. Do i place the test in M:\files\dev\products\kp\doctrine2\tests\Doctrine\Tests\ORM\Functional\Ticket?
Author
Owner

@deeky666 commented on GitHub (Jul 22, 2016):

Isn't it responsibility of QuotingStrategy to deal with that? IMO escaping of join columns has to be done in userland by a QuotingStrategy. We had issues like this a lot before already.

@deeky666 commented on GitHub (Jul 22, 2016): Isn't it responsibility of `QuotingStrategy` to deal with that? IMO escaping of join columns has to be done in userland by a `QuotingStrategy`. We had issues like this a lot before already.
Author
Owner

@michsk commented on GitHub (Jul 22, 2016):

The group column is not a join column it self. It is just a column in the table. But when calling a association of the option (ManyToMany self-referenceing) the escape quotes are removed from the associations.

And writing this. I did not have this problem with a different Entity which had many Options. So it looks like this has to do with self-referencing?

@michsk commented on GitHub (Jul 22, 2016): The group column is not a join column it self. It is just a column in the table. But when calling a association of the option (ManyToMany self-referenceing) the escape quotes are removed from the associations. And writing this. I did not have this problem with a different Entity which had many Options. So it looks like this has to do with self-referencing?
Author
Owner

@michsk commented on GitHub (Jul 22, 2016):

When i just return the association everything is fine:


    public function getRequiredOptions()
    {
        return $this->requiredOptions;//->matching($this->getRelationCriteria(Relation::get(Relation::DEPEND)));
    }

But when i use matching it does not escape the fields properly.

@michsk commented on GitHub (Jul 22, 2016): When i just return the association everything is fine: ``` php public function getRequiredOptions() { return $this->requiredOptions;//->matching($this->getRelationCriteria(Relation::get(Relation::DEPEND))); } ``` But when i use matching it does not escape the fields properly.
Author
Owner

@michsk commented on GitHub (Jul 25, 2016):

Is there maybe a difference betwee Sqlite and MySQL? When i play around with ManyToManySelfReferentialAssociationTest and the ECommerceProduct, i added a group property and that does seem to be quoted / escaped

@michsk commented on GitHub (Jul 25, 2016): Is there maybe a difference betwee Sqlite and MySQL? When i play around with `ManyToManySelfReferentialAssociationTest` and the `ECommerceProduct`, i added a `group` property and that does seem to be quoted / escaped
Author
Owner

@ostrolucky commented on GitHub (Aug 7, 2018):

In Doctrine 3.x, everything is quoted by default, which solves this issue

@ostrolucky commented on GitHub (Aug 7, 2018): In Doctrine 3.x, everything is quoted by default, which solves this issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5201