【发布时间】:2012-09-10 03:45:11
【问题描述】:
我有 3 个实体 Users、UserProfile 和 Staffs
用户配置文件通过用户 ID 链接到用户表 Staff 表使用 userprofileid 链接到 userprofile
管理员创建用户配置文件并生成注册号、用户名和密码。
我想将用户记录添加到用户表,然后添加用户个人资料,然后将个人资料 ID 添加到员工表。
我想按顺序保存三个实体
我尝试为喜欢的用户创建一个实例
$this->userent->setUsername('xxx');
$this->em->persist($this->userent);
$this->em->flush();
然后:
$this->profileent->setFirstname('xxx');
$this->em->persist($this->profileent);
$this->em->flush();
基本上三个实体之间共享一个表单,我想顺序插入三个表,
更新
除了users 实体之外,我还有一个链接到用户的usertype 实体...我只想保留外键。我有
setUserType(Usertype $userType)方法是users中user_type实体的一个实例
当我这样做时
$this->userent = new Users();
$this->userent->setUserType($this->em->getRepository('\Campus\Entity\Usertype')->findByUserType("admin"))
我得到了错误
Argument 1 passed to Campus\Entity\Users::setUserType() must be an instance of Campus\Entity\Usertype, array given
如果我传递作为 Usertype 实例的数组的值
我收到一条错误消息,说需要 ArrayCollection..help 的数组!!!
Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in D:\xampp\htdocs\zend\library\Doctrine\ORM\UnitOfWork.php on line 406 defined in D:\xampp\htdocs\zend\library\Doctrine\Common\Collections\ArrayCollection.php on line 46
【问题讨论】:
-
我其实很想知道如何坚持多个实体..
标签: php doctrine-orm