1

I have ClassA mapped to the entity ClassB with ManyToOne relation (simple so far).

class ClassA{ /** * @var string * @ORM\Id * @ORM\Column(name="keyA", type="string", length=255) */ private $keyA; /** * @var ClassB $classB * @ORM\ManyToOne(targetEntity="ClassB", inversedBy="classAs") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="ClassB_keyB", referencedColumnName="keyB") * }) */ private $classB; } 

And this is the ClassB:

class ClassB{ /** * @var string * @ORM\Id * @ORM\Column(name="keyB", type="string", length=255) */ private $keyB; /** * * @var ClassC $classC * @ORM\Id * @ORM\ManyToOne(targetEntity="ClassC", inversedBy="classBs") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="ClassC_keyC", referencedColumnName="keyC") * }) */ private $classC; /** * @var ArrayCollection $classAs * @ORM\OneToMany(targetEntity="ClassA", mappedBy="classB") */ private $classAs; } 

As you can notice the ClassB contains a composite primary key (2 entities and on column).
And this is the ClassC:

class ClassC{ /** * @var string * @ORM\Id * @ORM\Column(name="keyC", type="string", length=255) */ private $keyC; /** * @var ArrayCollection $classBs * @ORM\OneToMany(targetEntity="ClassB", mappedBy="classC") */ private $classBs; } 

Whene i try to display all entities of ClassA (using findAll()) I get this exception Missing value for primary key classC on ERP\................\ClassB

What am I missing here ?!

1 Answer 1

1

you have to create your own method at ClassARepository and add your join columns

Sign up to request clarification or add additional context in comments.

1 Comment

public function getClassA(){ return $this->createQueryBuilder('di') ->leftJoin('di.classB','ec') ->addSelect('ec') ->getQuery()->getResult(); }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.