I have a Class like the following:
/** @Entity **/
class orgGroup{
//id and stuff...
/**
* @Column(type=\"string\")
**/
private $name
Try to change fetch mode to EAGER.
@ORM\ManyToOne(targetEntity="****", fetch="EAGER").
It worked for me.
//Group.php ...
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->addJoinedGroup($this); /** VERY IMPORTANT **/
}
return $this;
}
Same in User.php
Without it, it didn't do anything in my database
Be sure to initialize the orgGroups collection in the orgGroupType entity
/**
* @OneToMany(targetEntity="orgGroup", mappedBy="_orgGroupType")
*/
protected $orgGroups ;
public function __construct() {
$this->orgGroups = new ArrayCollection();
}
You might need to include the following in the Entity
use Doctrine\Common\Collections\Collection,
Doctrine\Common\Collections\ArrayCollection;
This looks to me like a lazy-loading-issue. How do you get the data from the object into the Webservice answer?
Doctrine2 is lazy-loading if you don't configure something else, that means your $groups = $em->getRepository("orgGroup")->findAll();
won't return real orgGroup
objects, but Proxy objects (Doctrine Documentation).
That means a $group
object won't have it's description or orgGroupType value until you call $group->getDescription()
or $group->getOrgGroupType()
(then Doctrine loads them automatically), so you need to do that before writing the data into the JSON-response for the webservice. It won't work if you somehow loop through the object properties without using the getter methods.
I hope that was the problem :)