Skip to main content

I have ClassA set up an entity with a primary key consisting of two foreign keys but in this case iClassA mapped to the entity ClassB with one keyManyToOne 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; } 

ClassB with a composite primary keyAnd this is the ClassB: keyB and key consists of foreign key from ClassC.

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 triedtry to display index pageall entities of ClassA entity the errors log page of symfony (doctrineusing findAll()) indicateI get this errorexception Missing value for primary key classC on ERP\................\ClassB

This is a prototype demonstrationWhat am I missing here :)?!

I have ClassA set up an entity with a primary key consisting of two foreign keys but in this case i mapped with one key.

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; } 

ClassB with a composite primary key: keyB and key consists of foreign key from ClassC.

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; } 

//

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 tried to display index page of ClassA entity the errors log page of symfony (doctrine) indicate this error Missing value for primary key classC on ERP\................\ClassB

This is a prototype demonstration :)

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 ?!

added 54 characters in body
Source Link
isom
  • 304
  • 1
  • 13

I have ClassA set up an entity with a primary key consisting of two foreign keys but in this case i mapped with one key.

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; } 

ClassB with a composite primary key: keyB and key consists of foreign key from ClassC.

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; } 

class 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 tried to display index page of ClassA entity the errors log page of symfony (doctrine) indicate this error Missing value for primary key classC on ERP\................\ClassB

This is a prototype demonstration :)

I have ClassA set up an entity with a primary key consisting of two foreign keys but in this case i mapped with one key.

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; } 

ClassB with a composite primary key: keyB and key consists of foreign key from ClassC.

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; } 

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 tried to display index page of ClassA entity the errors log page of symfony (doctrine) indicate this error Missing value for primary key classC on ERP\................\ClassB

This is a prototype demonstration :)

I have ClassA set up an entity with a primary key consisting of two foreign keys but in this case i mapped with one key.

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; } 

ClassB with a composite primary key: keyB and key consists of foreign key from ClassC.

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; } 

//

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 tried to display index page of ClassA entity the errors log page of symfony (doctrine) indicate this error Missing value for primary key classC on ERP\................\ClassB

This is a prototype demonstration :)

Source Link
isom
  • 304
  • 1
  • 13

Doctrine 2 Composite Primary Keys as Foreign Key

I have ClassA set up an entity with a primary key consisting of two foreign keys but in this case i mapped with one key.

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; } 

ClassB with a composite primary key: keyB and key consists of foreign key from ClassC.

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; } 

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 tried to display index page of ClassA entity the errors log page of symfony (doctrine) indicate this error Missing value for primary key classC on ERP\................\ClassB

This is a prototype demonstration :)