Zend 1.11.11 Doctrine 2.1.2 关联代理实体的初始化
我遇到了这个奇怪的问题,关联实体是代理类,并且它的方法总是返回 null。我希望有人能对这个问题有所了解,因为它让我发疯。
我正在调用此代码:
$arrRoleResources = $em->getRepository("AJFIT\Entity\UserRoleResources")->findAll();
foreach($arrRoleResources as $roleResource) {
$name = $roleResource->getRoleFk()->getName();
}
即使当我调试代码时它会初始化代理类并且 $_identifier 具有正确的主键, $name 将始终为 null 。
UserRoleResources 实体:
namespace AJFIT\Entity;
/**
* UserRoleResources
* * @Table(name="user_role_resources")
* * @Entity(repositoryClass="AJFIT\Repository\UserRoleResources")
*/
class UserRoleResources {
/**
* @var UserRoles
*
* @ManyToOne(targetEntity="UserRoles")
* @JoinColumn(name="role_fk", referencedColumnName="pk")
*
*/
private $roleFk;
/**
* Get roleFk
*
* @return UserRoles $roleFk
*/
public function getRoleFk() {
return $this->roleFk;
}
}
UserRole 实体:
namespace AJFIT\Entity;
/**
* UserRoles
* * @Table(name="user_roles")
* * @Entity(repositoryClass="AJFIT\Repository\UserRoles")
*/
class UserRoles {
/**
* @var string $name
*
* @Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var integer $pk
*
* @Column(name="pk", type="integer")
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
private $pk;
/**
* Get name
*
* @return string $name
*/
public function getName() {
return $this->name;
}
}
我已遵循 zf-boilerplate 预编译示例,如果需要,我可以发布我的配置。
I am having this strange issue with an associative entity being a proxy class and its methods always returning null. I hope someone can shed a little light on the subject because it's driving me insane.
I am calling this code:
$arrRoleResources = $em->getRepository("AJFIT\Entity\UserRoleResources")->findAll();
foreach($arrRoleResources as $roleResource) {
$name = $roleResource->getRoleFk()->getName();
}
The $name will always be null even though when I debug the code it initializes the proxy class and the $_identifier is with the correct primary key.
UserRoleResources Entity:
namespace AJFIT\Entity;
/**
* UserRoleResources
* * @Table(name="user_role_resources")
* * @Entity(repositoryClass="AJFIT\Repository\UserRoleResources")
*/
class UserRoleResources {
/**
* @var UserRoles
*
* @ManyToOne(targetEntity="UserRoles")
* @JoinColumn(name="role_fk", referencedColumnName="pk")
*
*/
private $roleFk;
/**
* Get roleFk
*
* @return UserRoles $roleFk
*/
public function getRoleFk() {
return $this->roleFk;
}
}
UserRole Entity:
namespace AJFIT\Entity;
/**
* UserRoles
* * @Table(name="user_roles")
* * @Entity(repositoryClass="AJFIT\Repository\UserRoles")
*/
class UserRoles {
/**
* @var string $name
*
* @Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var integer $pk
*
* @Column(name="pk", type="integer")
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
private $pk;
/**
* Get name
*
* @return string $name
*/
public function getName() {
return $this->name;
}
}
I have followed the zf-boilerplate precompiled example, and i am able to post my config if required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的一些注释看起来有点错误。尝试修复这些...
类注释
失去额外的星号。
属性注释
将文档块直接放在属性上方(无空行)
Some of your annotations look a little wrong. Try fixing these up...
Class annotation
Lose the extra asterisks.
Property annotation
Place the docblocks directly above the properties (no blank lines)