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

Open
doctrinebot opened this Issue Feb 19, 2014 · 21 comments

4 participants

@doctrinebot

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.

@doctrinebot

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

Comment created by @ocramius:

[~calinpristavu] did you validate your mappings?

@doctrinebot

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

Comment created by litz:

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

@doctrinebot

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

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

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

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

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

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

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

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

Comment created by @ocramius:

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

@doctrinebot

Comment created by aivus:

I'll this ASAP.

@doctrinebot

Comment created by aivus:

Here is the test: #1307
Here is the test log on travis-ci: https://travis-ci.org/aivus/doctrine2/builds/51516067

@doctrinebot

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1307] was labeled:
#1307

@doctrinebot

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: #1307

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
@TriAnMan

I also suffer from this bug.

@beberlei is the fix proposed by dvaeversted available anywhere?

@kirkbushell

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment