I have a Class like the following:
/** @Entity **/
class orgGroup{
//id and stuff...
/**
* @Column(type="string")
**/
private $name;
/**
* @Column(type="string", nullable=true)
**/
private $description;
/**
* @ManyToOne(targetEntity="orgGroupType", inversedBy="_orgGroups")
* @JoinColumn(name="_orgGroupType")
**/
private $_orgGroupType;
//...
}
But when i load this Object from my database via
$groups = $em->getRepository("orgGroup")->findAll();
I just get the name correctly but not the _orgGroupType... and i dont know why... OrgGroup is the owner of orgGroupType and its just ONE object and not an array. My Webservice always just says:
{"error":[],"warning":[],"message":[],"data":[{"name":"AdministratorGroup","description":null,"_orgGroupType":{"__ isInitialized __":false}}]}
The result is:
"name":"AdministratorGroup",
"description":null,
"_orgGroupType":{"__ isInitialized __":false}
but should be:
"name":"AdministratorGroup",
"description":"some description",
"_orgGroupType":{name:"test"}
So there are 2 errors... and I have no idea why.
All the data is set correctly in the database.
Any Ideas?
EDIT:
Here's the missing code of my orgGroupType -entity
/** @Entity **/
class orgGroupType {
/**
* @OneToMany(targetEntity="orgGroup", mappedBy="_orgGroupType")
**/
private $_orgGroups;
public function __construct()
{
$this->_orgGroups = new ArrayCollection();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…