DDC-2988: Notice: Undefined index: joinColumns in BasicEntityPersister.php #3716

Open
opened 2026-01-22 14:26:04 +01:00 by admin · 28 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 19, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user dvaeversted:

When trying to use findBy on a ManyToMany field i receive the error:

Notice: Undefined index: joinColumns in lib/Doctrine/ORM/Persisters/BasicEntityPersister.php

It seems to be caused internally by the code expecting 'joinColumns' to be directly on the association, however it is found under 'joinTable'.
I have attached a patch that atleast fixes my case, hopefully it can be used to pin-point what the error is.

Originally created by @doctrinebot on GitHub (Feb 19, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user dvaeversted: When trying to use findBy on a ManyToMany field i receive the error: Notice: Undefined index: joinColumns in lib/Doctrine/ORM/Persisters/BasicEntityPersister.php It seems to be caused internally by the code expecting 'joinColumns' to be directly on the association, however it is found under 'joinTable'. I have attached a patch that atleast fixes my case, hopefully it can be used to pin-point what the error is.
admin added the Bug label 2026-01-22 14:26:04 +01:00
Author
Owner
@doctrinebot commented on GitHub (Feb 19, 2014): - duplicates [DDC-2808: Notice: Undefined index: joinColumns in Doctrine/ORM/Persisters/BasicEntityPersister.php line 1527 with many-to-many relation and contains criteria](http://www.doctrine-project.org/jira/browse/DDC-2808) - is referenced by [DDC-3578: [GH-1307] Test for DDC-2988](http://www.doctrine-project.org/jira/browse/DDC-3578)
Author
Owner

@doctrinebot commented on GitHub (Feb 19, 2014):

Comment created by dvaeversted:

Might be related to this one: http://www.doctrine-project.org/jira/browse/DDC-2808

@doctrinebot commented on GitHub (Feb 19, 2014): Comment created by dvaeversted: Might be related to this one: http://www.doctrine-project.org/jira/browse/[DDC-2808](http://www.doctrine-project.org/jira/browse/DDC-2808)
Author
Owner

@doctrinebot commented on GitHub (May 28, 2014):

Comment created by litz:

Doctrine ORM 2.4.2 Here.

Here are my annotations
https://gist.github.com/LitzOuille/3cf2e73e169c032147ea

The thing I'm trying to do is
$questionRepository->findBy(array('contacts' => $ids)); // $ids = array(1,2,3, ...)

@doctrinebot commented on GitHub (May 28, 2014): Comment created by litz: Doctrine ORM 2.4.2 Here. Here are my annotations https://gist.github.com/LitzOuille/3cf2e73e169c032147ea The thing I'm trying to do is $questionRepository->findBy(array('contacts' => $ids)); // $ids = array(1,2,3, ...)
Author
Owner

@doctrinebot commented on GitHub (May 30, 2014):

Comment created by @ocramius:

[~calinpristavu] did you validate your mappings?

@doctrinebot commented on GitHub (May 30, 2014): Comment created by @ocramius: [~calinpristavu] did you validate your mappings?
Author
Owner

@doctrinebot commented on GitHub (May 30, 2014):

Comment created by calinpristavu:

I failed, sorry.
The error came from the many-to-many condition in the entity.
Sorry for generating confusion, comment deleted !

The many-to-one works just fine !

@doctrinebot commented on GitHub (May 30, 2014): Comment created by calinpristavu: I failed, sorry. The error came from the many-to-many condition in the entity. Sorry for generating confusion, comment deleted ! The many-to-one works just fine !
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2014):

Comment created by litz:

A little feedback? Is this a bug? Can it be fixed?
Thanks

@doctrinebot commented on GitHub (Jun 3, 2014): Comment created by litz: A little feedback? Is this a bug? Can it be fixed? Thanks
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2014):

Comment created by @ocramius:

[litz] that particular repository call cannot work. How are we supposed to find an entity from a list of associated IDs? It would have to be the exact match...

Assuming that API would work as I envision it, it looks like a missing feature.

[dvaeversted] in order to accept a patch, we first need a failing test case demonstrating the failing scenario.

@doctrinebot commented on GitHub (Jun 3, 2014): Comment created by @ocramius: [<sub>litz] that particular repository call cannot work. How are we supposed to find an entity from a list of associated IDs? It would have to be the exact match... Assuming that API would work as I envision it, it looks like a missing feature. [</sub>dvaeversted] in order to accept a patch, we first need a failing test case demonstrating the failing scenario.
Author
Owner

@doctrinebot commented on GitHub (Jun 3, 2014):

Comment created by litz:

EDIT: Ok my bad.

I am using findBy(array('id', $arrayIds)) and it is working. I thought I was using on a ManyToOne relationship, but no.

EDIT2: @ocramius In fact I would like to find all questions for which the contacts' list contains at least one id. Something like
SELECT q.*
FROM Question q, QuestionContact qc //qc = jointable
WHERE q.id = qc.question_id
AND qc.contact_id IN ($ids)

EDIT3: Actually when I try to findBy('ManyToMany', $id), it does not work either. I think I will have to use a repository for every query using a ManyToMany relationship.

EDIT4: Ok, so, as said in the original post, findBy does not work with many-to-many.
Notice: Undefined index: joinColumns (BasicEntityPersister.php line 1666)
Dump($this->class->associationMappings[$field]): https://gist.github.com/LitzOuille/51929fdc3eda5576ed31

@doctrinebot commented on GitHub (Jun 3, 2014): Comment created by litz: EDIT: Ok my bad. I am using findBy(array('id', $arrayIds)) and it is working. I thought I was using on a ManyToOne relationship, but no. EDIT2: @ocramius In fact I would like to find all questions for which the contacts' list contains at least one id. Something like SELECT q.* FROM Question q, QuestionContact qc //qc = jointable WHERE q.id = qc.question_id AND qc.contact_id IN ($ids) EDIT3: Actually when I try to findBy('ManyToMany', $id), it does not work either. I think I will have to use a repository for every query using a ManyToMany relationship. EDIT4: Ok, so, as said in the original post, findBy does not work with many-to-many. Notice: Undefined index: joinColumns (BasicEntityPersister.php line 1666) Dump($this->class->associationMappings[$field]): https://gist.github.com/LitzOuille/51929fdc3eda5576ed31
Author
Owner

@doctrinebot commented on GitHub (Jun 13, 2014):

Comment created by Eversor:

I've got the same issue, also running doctrine 2.4.2:

multiple users can have multiple departments:

/****
 * @ORM\ManyToMany(targetEntity="CartelAuthDepartment", inversedBy="users")
 * @ORM\JoinTable(name="cartel*auth_user_has_cartel_auth*department",
 *      joinColumns={@ORM\JoinColumn(name="cartel*auth_user*id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="cartel*auth_department*id", referencedColumnName="id")}
 * )
 */
private $departments;

/****
 * @ORM\ManyToMany(targetEntity="\Cartel\AuthBundle\Entity\CartelAuth\CartelAuthUser", mappedBy="departments")
 */
private $users;

Then I want to find all the users that are within the departments that the current user has:

$aAuthUsers = $oEm->getRepository('CartelAuthBundle:CartelAuth\CartelAuthUser')->findByDepartments($aAuthDepartments);

This results in this error:

{quote}
Notice: Undefined index: joinColumns in .../vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1665
{quote}

@doctrinebot commented on GitHub (Jun 13, 2014): Comment created by Eversor: I've got the same issue, also running doctrine 2.4.2: multiple users can have multiple departments: ``` /**** * @ORM\ManyToMany(targetEntity="CartelAuthDepartment", inversedBy="users") * @ORM\JoinTable(name="cartel*auth_user_has_cartel_auth*department", * joinColumns={@ORM\JoinColumn(name="cartel*auth_user*id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="cartel*auth_department*id", referencedColumnName="id")} * ) */ private $departments; /**** * @ORM\ManyToMany(targetEntity="\Cartel\AuthBundle\Entity\CartelAuth\CartelAuthUser", mappedBy="departments") */ private $users; ``` Then I want to find all the users that are within the departments that the current user has: ``` $aAuthUsers = $oEm->getRepository('CartelAuthBundle:CartelAuth\CartelAuthUser')->findByDepartments($aAuthDepartments); ``` This results in this error: {quote} Notice: Undefined index: joinColumns in .../vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1665 {quote}
Author
Owner

@doctrinebot commented on GitHub (Jan 29, 2015):

Comment created by Scooty:

I have same problem with doctrine 2.4.7:

  manyToMany:
    projectbag:
      targetEntity: ProjectBag
      mappedBy: bagemployee
Acme\ProjectBundle\Entity\ProjectBag:
  manyToMany:
    bagemployee:
          targetEntity: Employee
          inversedBy: projectbag
          joinTable:
            name: ProjectBag_Employee
            joinColumns:
              ProjectBag_id:
                referencedColumnName: id
            inverseJoinColumns:
              Employee_id:
                referencedColumnName: id

$em->getRepository('AcmeProjectBundle:ProjectBag')->findBy(array('bagemployee'=>$em->getRepository('AcmeProjectBundle:Employee')->find(828)));

Notice: Undefined index: joinColumns in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php at line 1670

@doctrinebot commented on GitHub (Jan 29, 2015): Comment created by Scooty: I have same problem with doctrine 2.4.7: ``` Acme\ProjectBundle\Entity\Employee: manyToMany: projectbag: targetEntity: ProjectBag mappedBy: bagemployee Acme\ProjectBundle\Entity\ProjectBag: manyToMany: bagemployee: targetEntity: Employee inversedBy: projectbag joinTable: name: ProjectBag_Employee joinColumns: ProjectBag_id: referencedColumnName: id inverseJoinColumns: Employee_id: referencedColumnName: id $em->getRepository('AcmeProjectBundle:ProjectBag')->findBy(array('bagemployee'=>$em->getRepository('AcmeProjectBundle:Employee')->find(828))); ``` Notice: Undefined index: joinColumns in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php at line 1670
Author
Owner

@doctrinebot commented on GitHub (Feb 6, 2015):

Comment created by geoB:

What is meant by "Awaiting feedback"?

After encountering the same error as described above I've created a new Symfony project with the sole purpose of reproducing the error. If this would be of use in resolving the issue please let me know. I can make the code available in whatever form would be the most useful.

@doctrinebot commented on GitHub (Feb 6, 2015): Comment created by geoB: What is meant by "Awaiting feedback"? After encountering the same error as described above I've created a new Symfony project with the sole purpose of reproducing the error. If this would be of use in resolving the issue please let me know. I can make the code available in whatever form would be the most useful.
Author
Owner

@doctrinebot commented on GitHub (Feb 6, 2015):

Comment created by @ocramius:

{quote}in order to accept a patch, we first need a failing test case demonstrating the failing scenario.{quote}

We don't need a symfony project or an example app: we have our own test suite that can be found at https://github.com/doctrine/doctrine2/tree/master/tests

@doctrinebot commented on GitHub (Feb 6, 2015): Comment created by @ocramius: {quote}in order to accept a patch, we first need a failing test case demonstrating the failing scenario.{quote} We don't need a symfony project or an example app: we have our own test suite that can be found at https://github.com/doctrine/doctrine2/tree/master/tests
Author
Owner

@doctrinebot commented on GitHub (Feb 13, 2015):

Comment created by cboisvert:

I have the same issue. Want to filter on a relationship on the owning side (Because I got an error on the non owning side saying I needed to be on the owning side) and I get the exact same error.

@doctrinebot commented on GitHub (Feb 13, 2015): Comment created by cboisvert: I have the same issue. Want to filter on a relationship on the owning side (Because I got an error on the non owning side saying I needed to be on the owning side) and I get the exact same error.
Author
Owner

@doctrinebot commented on GitHub (Feb 19, 2015):

Comment created by aivus:

As workaround we can collect IDs and pass it to queryBuilder, like:

    public function findAllSwitcherTypeByComponents($components)
    {
        $ids = [];
        /*** @var Component $component **/
        foreach ($components as $component) {
            $ids[] = $component->getId();
        }

        $query = $this->createQueryBuilder('component*switcher*type');
        $query
            ->join( 'component*switcher*type.components', 'components', 'WITH', $query->expr()->in('components.id', $ids));

        return $query->getQuery()->getResult();
}
@doctrinebot commented on GitHub (Feb 19, 2015): Comment created by aivus: As workaround we can collect IDs and pass it to queryBuilder, like: ``` public function findAllSwitcherTypeByComponents($components) { $ids = []; /*** @var Component $component **/ foreach ($components as $component) { $ids[] = $component->getId(); } $query = $this->createQueryBuilder('component*switcher*type'); $query ->join( 'component*switcher*type.components', 'components', 'WITH', $query->expr()->in('components.id', $ids)); return $query->getQuery()->getResult(); } ```
Author
Owner

@doctrinebot commented on GitHub (Feb 19, 2015):

Comment created by @ocramius:

Don't code workarounds: provide a test case, so that a patch can be created ;-)

@doctrinebot commented on GitHub (Feb 19, 2015): Comment created by @ocramius: Don't code workarounds: provide a test case, so that a patch can be created ;-)
Author
Owner

@doctrinebot commented on GitHub (Feb 19, 2015):

Comment created by aivus:

I'll this ASAP.

@doctrinebot commented on GitHub (Feb 19, 2015): Comment created by aivus: I'll this ASAP.
Author
Owner

@doctrinebot commented on GitHub (Feb 20, 2015):

Comment created by aivus:

Here is the test: https://github.com/doctrine/doctrine2/pull/1307
Here is the test log on travis-ci: https://travis-ci.org/aivus/doctrine2/builds/51516067

@doctrinebot commented on GitHub (Feb 20, 2015): Comment created by aivus: Here is the test: https://github.com/doctrine/doctrine2/pull/1307 Here is the test log on travis-ci: https://travis-ci.org/aivus/doctrine2/builds/51516067
Author
Owner

@doctrinebot commented on GitHub (Mar 16, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1307] was labeled:
https://github.com/doctrine/doctrine2/pull/1307

@doctrinebot commented on GitHub (Mar 16, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1307] was labeled: https://github.com/doctrine/doctrine2/pull/1307
Author
Owner

@doctrinebot commented on GitHub (May 26, 2015):

Comment created by aivus:

On master branch getting this error now:

Column not found: 1054 Unknown column 'users*to_groups.group*id' in 'where clause'

for this test: https://github.com/doctrine/doctrine2/pull/1307

@doctrinebot commented on GitHub (May 26, 2015): Comment created by aivus: On master branch getting this error now: ``` Column not found: 1054 Unknown column 'users*to_groups.group*id' in 'where clause' ``` for this test: https://github.com/doctrine/doctrine2/pull/1307
Author
Owner

@TriAnMan commented on GitHub (Feb 8, 2016):

I also suffer from this bug.

@beberlei is the fix proposed by dvaeversted available anywhere?

@TriAnMan commented on GitHub (Feb 8, 2016): I also suffer from this bug. @beberlei is the fix proposed by dvaeversted available anywhere?
Author
Owner

@kirkbushell commented on GitHub (Mar 26, 2016):

I'm seeing this atm. Is this still an issue!?

@kirkbushell commented on GitHub (Mar 26, 2016): I'm seeing this atm. Is this still an issue!?
Author
Owner

@shakaran commented on GitHub (Oct 13, 2017):

This is still an issue to me in ^2.5 version.

I found the temporal workaround here:

https://stackoverflow.com/questions/10806881/one-to-one-self-referencing-bi-directional-relationship

In my case I have a entity Folder, that store an attribute called "parent", which self reference to the same entity folder in bidirectional.

So I solve like:

    oneToOne:
        parent:
            mappedBy: next
            inversedBy: parent
            targetEntity: Folder
            cascade:      [persist]
            joinTable:
              name: folder_folder
              joinColumns:
                folder_id:
                  referencedColumnName: id
              inverseJoinColumns:
                parent_id:
                  referencedColumnName: id   
        next:   
          targetEntity: Folder
          inversedBy: parent   

Also notice that $this->currentPersisterContext doesn't have any info in the $association array to index joinColumns even if you define the joinColumns for the LEFT JOIN. So it is totally failuring for self reference bidirectional:

$this->currentPersisterContext->selectJoinSql .= ' LEFT JOIN';

foreach ($association['joinColumns'] as $joinColumn) {
@shakaran commented on GitHub (Oct 13, 2017): This is still an issue to me in ^2.5 version. I found the temporal workaround here: https://stackoverflow.com/questions/10806881/one-to-one-self-referencing-bi-directional-relationship In my case I have a entity Folder, that store an attribute called "parent", which self reference to the same entity folder in bidirectional. So I solve like: ```yaml oneToOne: parent: mappedBy: next inversedBy: parent targetEntity: Folder cascade: [persist] joinTable: name: folder_folder joinColumns: folder_id: referencedColumnName: id inverseJoinColumns: parent_id: referencedColumnName: id next: targetEntity: Folder inversedBy: parent ``` Also notice that $this->currentPersisterContext doesn't have any info in the $association array to index joinColumns even if you define the joinColumns for the LEFT JOIN. So it is totally failuring for self reference bidirectional: ```php $this->currentPersisterContext->selectJoinSql .= ' LEFT JOIN'; foreach ($association['joinColumns'] as $joinColumn) { ```
Author
Owner

@lcobucci commented on GitHub (Oct 29, 2017):

@shakaran could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.

You can find examples on 388afb46d0/tests/Doctrine/Tests/ORM/Functional/Ticket

@lcobucci commented on GitHub (Oct 29, 2017): @shakaran could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing. You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket
Author
Owner

@shakaran commented on GitHub (Oct 30, 2017):

@lcobucci not sure if the failing test could be used as YAML? There are some particular example which I could use as YAML loading example? I describe above the YAML needed and the stackoveflow question has another example too.

@shakaran commented on GitHub (Oct 30, 2017): @lcobucci not sure if the failing test could be used as YAML? There are some particular example which I could use as YAML loading example? I describe above the YAML needed and the stackoveflow question has another example too.
Author
Owner

@Majkl578 commented on GitHub (Dec 9, 2017):

@shakaran Please map the failing test using annotations or XML only, YAML support is going to be removed in Doctrine 3.0. It's pretty straightforward to map entites using annotations, most of the tests in the folder linked above will serve as great examples.

@Majkl578 commented on GitHub (Dec 9, 2017): @shakaran Please map the failing test using annotations or XML only, YAML support is going to be removed in Doctrine 3.0. It's pretty straightforward to map entites using annotations, most of the tests in the folder linked above will serve as great examples.
Author
Owner

@mpdude commented on GitHub (Jun 26, 2023):

A current version of the test against 2.15 is in #10801.

@mpdude commented on GitHub (Jun 26, 2023): A current version of the test against 2.15 is in #10801.
Author
Owner

@mpdude commented on GitHub (Jun 26, 2023):

I guess it comes down to this question:

When you call \Doctrine\ORM\EntityRepository::findBy() and pass a criteria like ['groups' => [$group1, $group2]], what would we expect to happen when groups refers to a many-to-many association?

Find all users that have one of the given groups in their list of groups, or all of them?

Can we define it in a way that would be consistent with other association types?

@mpdude commented on GitHub (Jun 26, 2023): I guess it comes down to this question: When you call `\Doctrine\ORM\EntityRepository::findBy()` and pass a criteria like `['groups' => [$group1, $group2]]`, what would we expect to happen when `groups` refers to a many-to-many association? Find all users that have _one_ of the given groups in their list of groups, or _all_ of them? Can we define it in a way that would be consistent with other association types?
Author
Owner

@mpdude commented on GitHub (Jun 27, 2023):

The more I look at it, the more I believe that EntityPersister::load() was never designed to support criteria aiming at for association fields, at least not collection-values ones. Maybe to-one collections work (by coindicence?) because the referred-to entity identifier is available as a plain value in the referring table.

The fact that we have something that looks related to many-to-many handling in \Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getSelectConditionStatementColumnSQL comes from #1249: It's used when when coming from a CollectionPersister to find the entities referred-to by that collection.

@beberlei @guilhermeblanco if you agree then proably the best we can do about this is to reject such criteria with a meaningful exception message and update documentation to mention this as a limitation.

@mpdude commented on GitHub (Jun 27, 2023): The more I look at it, the more I believe that `EntityPersister::load()` was never designed to support criteria aiming at for association fields, at least not collection-values ones. Maybe to-one collections work (by coindicence?) because the referred-to entity identifier is available as a plain value in the referring table. The fact that we have something that looks related to many-to-many handling in `\Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getSelectConditionStatementColumnSQL` comes from #1249: It's used when when coming from a CollectionPersister to find the entities referred-to by that collection. @beberlei @guilhermeblanco if you agree then proably the best we can do about this is to reject such criteria with a meaningful exception message and update documentation to mention this as a limitation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3716