我有一个叫做SourceElanceProfileImport的实体,我在动作中创建了这个实体并设置了一些数据,但是当我执行flush操作时出现了错误:
Catchable Fatal Error: Object of class Proxies\__CG__\Artel\ProfileBundle\Entity\Teams could not be converted to string
有一个问题,为什么我发现像这样的团队后,我就有代理对象?
$team = $em->getRepository('ArtelProfileBundle:Teams')->findOneById($id);
我努力编写了一个id,但是没有实体Teams
$id = '2';
$team = $em->getRepository('ArtelProfileBundle:Teams')->findOneById($id);
// $team entity Teams, not Proxies
发生了什么问题,导致这个操作出现了错误?
操作:
public function elanceProfileAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$url = $request->get('url');
$email = $request->get('email');
$firstName = $request->get('firstName');
$user = $em->getRepository('ArtelProfileBundle:Users')->getCompanyByEmail($request->get('email'));
$id = $user[0]->getTeams()->getId();
$team = $em->getRepository('ArtelProfileBundle:Teams')->findOneById($id);
if (!empty($user)) {
$elance_import = new SourceElanceProfileImport();
$hepler = $this->container->get('artel.profile.additional_function');
$pass = $hepler->generatePassword();
$elance_import
->setEmail($email)
->setSecurityHash(sha1($pass))
->setElanceUrl($url)
->setTeamId($team)
;
$em->persist($elance_import);
$em->flush();
实体:
class SourceElanceProfileImport
{
/**
* @var \Teams
*
* @ORM\ManyToOne(targetEntity="Teams")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="team_id", referencedColumnName="id", onDelete="CASCADE")
* })
*/
private $teamId;
/**
* @var integer
*
* @ORM\Column(name="team_id", type="integer")
*/
public $team;
当我在实体团队(Teams)中添加__toString时,会得到以下结果:
public function __toString()
{
return $this->company;
}
Error in one or more bulk request actions:
index: /aog/sourceelanceprofileimport/5 caused MapperParsingException[failed to parse [team_id]]; nested: NumberFormatException[For input string: "Gutkowski LLC"];
为什么在另一个实体中可以正常工作,但是我不知道出了什么问题((
更新 我解决了,但我认为这个解决方案并不完美,所以我没有删除这个问题。 我在用户实体中添加了:
private function _load()
{
// lazy loading code
}
/**
* Get teams
*
* @return \Artel\ProfileBundle\Entity\Teams
*/
public function getLoadTeams()
{
$this->_load();
return parent::getId();
}
在我的操作中
$user = $em->getRepository('ArtelProfileBundle:Users')->getCompanyByEmail($request->get('email'));
$id = $user[0]->getLoadTeams();
$team = $em->getRepository('ArtelProfileBundle:Teams')->findOneById($id);
我在变量 $team 中有一个 Teams 对象,但是当我刷新时仍然出现错误:
Catchable Fatal Error: Object of class Artel\ProfileBundle\Entity\Teams could not be converted to string