Doctrine2 challenge, I have OneToMany but not ManyToOne,
You have a messaging system where messages can belong to consultations, but you don't need to. All consultations have 1 or more posts though ...
My objects were generated automatically by Doctrine, but it vendor/bin/doctrine-module orm:validate-schema
does not fire correctly ...
vendor/bin/doctrine-module orm:validate-schema
[Mapping] FAIL - The entity-class 'Legetimen\Entity\Konsultasjon' mapping is invalid:
* The association Legetimen\Entity\Konsultasjon#meldinger refers to the owning side field Legetimen\Entity\Meldinger#konsulatsjon which is not defined as association, but as field.
* The association Legetimen\Entity\Konsultasjon#meldinger refers to the owning side field Legetimen\Entity\Meldinger#konsulatsjon which does not exist.
[Database] FAIL - The database schema is not in sync with the current mapping file.
Determining the relevant associations: From posts / Meldinger:
/**
* @var integer
*
* @ORM\Column(name="konsulatsjon", type="integer", precision=0, scale=0, nullable=true, unique=false)
* @ORM\ManyToOne(targetEntity="Konsultasjon", inversedBy="konsultasjonid")
*/
private $konsulatsjon;
From my "parental" consultation Consultation:
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Legetimen\Entity\Meldinger", mappedBy="konsulatsjon", cascade={"persist"}, fetch="EAGER")
*/
private $meldinger;
My konsultasjon is showing up with someone else's trigger, but not my posts (because many of the konsultasjon are NULL).
Also there is very little I can do to write, as it is a legacy and a rather messy application ...
Please let me know if you need anything else and any help would be greatly appreciated.
[EDIT] Removed @var and @collumn in posts (Meldinger) as chained to comments ended up with this result:
vendor/bin/doctrine-module orm:validate-schema
[Mapping] FAIL - The entity-class 'Legetimen\Entity\Konsultasjon' mapping is invalid:
* The mappings Legetimen\Entity\Konsultasjon#meldinger and Legetimen\Entity\Meldinger#konsulatsjon are inconsistent with each other.
[Mapping] FAIL - The entity-class 'Legetimen\Entity\Meldinger' mapping is invalid:
* The association Legetimen\Entity\Meldinger#konsulatsjon refers to the inverse side field Legetimen\Entity\Konsultasjon#konsultasjonid which is not defined as association.
* The association Legetimen\Entity\Meldinger#konsulatsjon refers to the inverse side field Legetimen\Entity\Konsultasjon#konsultasjonid which does not exist.
* The referenced column name 'id' has to be a primary key column on the target entity class 'Legetimen\Entity\Konsultasjon'.
[Doctrine\ORM\ORMException]
Column name `id` referenced for relation from Legetimen\Entity\Meldinger towards Legetimen\Entity\Konsultasjon does not exist.
orm:validate-schema
Konsultasjon ID:
/**
* @var integer
*
* @ORM\Column(name="konsultasjonid", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $konsultasjonid;
Message ID / Meldinger
/**
* @var integer
*
* @ORM\Column(name="meldingerid", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $meldingerid;
source to share
If you are not using $id
your entity as the primary key, you must use annotation JoinColumn
to set up the relationship between entities. JoinColumn .
If you want to change the column name of a relationship property, you need to use JoinColumn
annotation instead Column
.
class Meldinger {
/**
* @var integer
*
* @ORM\Column(name="meldingerid", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $meldingerid;
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="Konsultasjon", inversedBy="meldinger")
* @JoinColumn(name="konsulatsjon", referencedColumnName="konsulatsjonid")
*/
private $konsulatsjon;
}
class Konsultasjon {
/**
* @var integer
*
* @ORM\Column(name="konsultasjonid", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $konsultasjonid;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Legetimen\Entity\Meldinger", mappedBy="konsulatsjon", cascade={"persist"}, fetch="EAGER")
* @JoinColumn(name="meldinger", referencedColumnName="meldingerid")
*/
private $meldinger;
}
PS.
I also adjusted the parameters @ManyToOne
for Meldinger
.
source to share