我有 2 个实体
/**
* @ORM\Entity(repositoryClass="FLI\ContractBundle\Repository\CarrierFuelRepository")
* @ORM\Table(name="carrier_fuel")
*/
class CarrierFuel
{
/**
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $title;
/**
* @ORM\ManyToOne(targetEntity="FuelIndex")
*/
protected $index;
/**
* @ORM\OneToMany(targetEntity="FuelLine", mappedBy="carrier_fuel", cascade={"persist", "remove"})
*/
protected $fuel_lines;
}
/**
* @ORM\Entity(repositoryClass="FLI\ContractBundle\Repository\FuelLineRepository")
* @ORM\Table(name="fuel_line")
*/
class FuelLine
{
/**
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="CarrierFuel", inversedBy="fuel_lines")
*/
protected $carrier_fuel;
}
这是我的表单处理程序中的代码:
public function process(CarrierFuel $fuel)
{
$this->form->setData($fuel);
if ('POST' === $this->request->getMethod())
{
$this->form->bind($this->request);
if ($this->form->isValid())
{
$this->em->persist($fuel);
$this->em->flush();
return true;
}
}
return false;
}
我遇到的问题是它没有在拥有方(fuel_line)上设置外键(carrier_fuel_id)。运行上述处理方法时出现此错误。
An exception occurred while executing 'INSERT INTO fuel_line (id, min, max, ltl_surcharge, carrier_fuel_id) VALUES (?, ?, ?, ?, ?)' with params [14, "4", "4", "4", null]:
SQLSTATE[42703]: Undefined column: 7 ERROR: column "carrier_fuel_id" of relation "fuel_line" does not exist
LINE 1: ...SERT INTO fuel_line (id, min, max, ltl_surcharge, carrier_fu...
(编辑)我更新了 setFuelLine 设置器以设置carrier_fuel id,但现在它似乎试图在实际插入carrier_fuel 行之前保存fuel_line。
使用参数 [26、“4”、“4”、“4”、 29]:
SQLSTATE [42703]:未定义列:7 错误:关系“fuel_line”的列“carrier_fuel_id”不存在第 1 行:...SERT INTOfuel_line(id、min、max、ltl_surcharge、carrier_fu ...