I have 2 Entities
/**
* @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;
}
And this is code in my form handler:
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;
}
The issue im having is its not setting the foreign key (carrier_fuel_id) on the owning side (fuel_line). I get this error when running the process method above.
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...
(EDIT) I updated the setFuelLine setter to set the carrier_fuel id, but now it seems like it tries to save the fuel_line before actually inserting the carrier_fuel row.
An exception occurred while executing 'INSERT INTO fuel_line (id, min, max, ltl_surcharge, carrier_fuel_id) VALUES (?, ?, ?, ?, ?)' with params [26, "4", "4", "4", 29]:
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...