更新关系映射后,Symfony 2的学说持续不起作用 [英] Symfony 2 doctrine persist doesn't work after updating Relationship Mapping
本文介绍了更新关系映射后,Symfony 2的学说持续不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我更新了我的实体文件以包括关系映射。
I updated my entity file to include relationship mapping.
Persist在更新之前工作,现在没有。
Persist worked before the update now it doesn't.
也许这是我忘了做的。
namespace classes\classBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* advisersplans
*
* @ORM\Table()
* @ORM\Entity
*/
class advisersPlans
{
/**
*
* @ORM\ManyToOne(targetEntity="plans", inversedBy="adviserPlans")
* @ORM\JoinColumn(name="planid", referencedColumnName="id")
*/
public $plan;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @var integer
*
* @ORM\Column(name="userid", type="integer")
*
*
*/
public $userid;
/**
* @var integer
*
* @ORM\Column(name="adviserid", type="integer")
*
*
*/
public $adviserid;
/**
* @var integer
*
* @ORM\Column(name="planid", type="integer")
*
*
*/
public $planid;
/**
* @var string
*
* @ORM\Column(name="participantLoginWebsiteAddress", type="string", length=255)
*/
public $participantLoginWebsiteAddress;
public function __construct()
{
$class_vars = get_class_vars(get_class($this));
foreach ($class_vars as $key => $value)
{
if ($key != "plan")
$this->$key = "";
}
}
}
Perist返回错误,说planid为null。如果我删除以下内容,可以使用。
Perist returns error saying planid is null. If I remove the following it works.
/**
*
* @ORM\ManyToOne(targetEntity="plans", inversedBy="adviserPlans")
* @ORM\JoinColumn(name="planid", referencedColumnName="id")
*/
这是我的代码,而坚持。
Here is my code while persisting.
$adviserPlan = new advisersPlans();
$adviserPlan->planid = $planid;
$adviserPlan->userid = $this->userid();
$adviserPlan->adviserid = $session->get("editadviserid");
$em->persist($adviserPlan);
我应该填写计划字段而不是平面字段,或者我的实体文件编码错误。 >
Am I supposed to populate the plan field and not the planid field or is my entity file coded wrong.
推荐答案
你不应该设置ids。您应该设置实体:
You shouldn't set ids. You should set entities:
$adviserPlan = new advisersPlans();
// You should retrieve the plan before doing this, of course.
$adviserPlan->setPlan($plan);
$plans->addAdviserPlan(§adviserPlan);
$em->persist($adviserPlan);
当您运行以下命令时,应该由doctrine生成将集合添加到实体的方法:
The methods for adding an entity to a collection should be generated by doctrine when you run:
php app/console doctrine:generate:entities YourBundle
这篇关于更新关系映射后,Symfony 2的学说持续不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文