I'm new here and quite new to symfony 2.
I try to build an Entity 'MailProcess' that inherits from an Entity 'Process'. Here are my Entity definitions:
// src/MW/TodoBundle/Entity/Process.php
namespace MW\TodoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="process_type", type="string")
* @ORM\DiscriminatorMap({"mailprocess" = "MailProcess", "process" = "Process"})
* @ORM\Table(name="process")
* @ORM\HasLifecycleCallbacks
*/
class Process
{
/**
*
* @ORM\Id
* @ORM\Column(type="integer", unique=true)
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
*
* @ORM\Column(type="string")
*/
protected $title;
/**
*
* @ORM\Column(type="datetime")
*/
protected $created;
/**
*
* @ORM\Column(type ="text", nullable= true)
*/
protected $comment;
protected $options;
// Getters and Setters
}
// src/MW/TodoBundle/Entity/MailProcess.php
namespace MW\TodoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use MW\TodoBundle\Entity\Process;
/**
*
* @ORM\Entity
* @ORM\Table(name="process_mailprocess")
*/
class MailProcess extends Process
{
/**
*
* @ORM\Column(type="string")
*/
protected $from;
/**
*
* @ORM\Column(type="string")
*/
protected $to;
/**
*
* @ORM\Column(type="string", nullable=true)
*/
protected $subject;
/**
*
* @ORM\Column(type="text", nullable=true)
*/
protected $message;
}
You can see the ORM Class Table Inheritance used: Two tables 'process' and 'process_mailprocess' with discriminator column 'process_type'.
I do use ´php app/console doctrine:schema:update --force´ to update the schema to my MySQL database which works fine.
But then there are my Data fixtures: I've stripped them down to one here, but be assured I have additional fixtures also testing the Entity 'Process' which are working fine.
// src/MW/TodoBundle/DataFixtures/ORM/ProcessFixtures.php
namespace MW\TodoBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use MW\TodoBundle\Entity\Process;
use MW\TodoBundle\Entity\MailProcess;
class ProcessFixtures implements FixtureInterface
{
public function load(ObjectManager $manager)
{
$mp1= new MailProcess();
$mp1->setTitle("Invoice from heaven")
->setComment("sitebot: Irgendwer will was von euch!")
->setCreated(new \DateTime())
->setFrom("m")
->setTo("m")
->setSubject("m")
->setMessage("m");
$manager->persist($mp1);
$manager->flush();
}
}
Alas, execution of ´php app/console doctrine:fixtures:load´ confirming 'y' to purge gets me
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'INSERT INTO process_mailprocess (id, from, to, subject, message) VALUES (?,
?, ?, ?, ?)' with params {"1":28,"2":"m","3":"m","4":"m","5":"m"}:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'from, to, subject, message) VALUES ('28
', 'm', 'm', 'm', 'm')' at line 1
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'from, to, subject, message) VALUES ('28
', 'm', 'm', 'm', 'm')' at line 1
I can see nothing wrong there, and besides, Doctrine and Symfony create the SQL query. Can anyone point me to what I am doing wrong here? This is a real head-scratcher for me.