I have ManyToMany Association between Entities “Consultant” and “Status”
which defined as follows:
@ORM\ManyToMany(targetEntity="Status", inversedBy="consultant")
@ORM\JoinTable(name="consultant_status",
joinColumns={
@ORM\JoinColumn(name="consultant_id", referencedColumnName="id")
},
inverseJoinColumns={
@ORM\JoinColumn(name="status_id", referencedColumnName="id")
}
)
when I try(on Doctrine postUpdate event) to get an id from Status, with the following way:
...
$entity = $args->getEntity();
if($entity instanceof Consultant){
$status_id= $entity->getStatu()->getId();
}
...
I get:
Call to undefined method Doctrine\ORM\PersistentCollection::::getId()
Does anybody know what I do wrong?
As Consultant and Status are in a ManyToMany relation,
getStatus()will return aCollectionobject with all the status related to this Consultant.To loop throught all your statut just use foreach