我是新来的,对 symfony 2 很陌生。
我尝试构建一个从实体“进程”继承的实体“邮件进程”。这是我的实体定义:
// 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;
}
您可以看到使用的 ORM 类表继承:两个表 'process' 和 'process_mailprocess' 带有鉴别器列 'process_type'。
我确实使用 'php app/console dictionary:schema:update --force' 将架构更新到我的 MySQL 数据库,这工作正常。
但是还有我的数据装置:我在这里将它们剥离为一个,但请放心,我还有其他装置也在测试运行良好的实体“进程”。
// 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();
}
}
唉,执行“php app/console 原则:fixtures:load”确认“y”清除让我
[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
我看不出有什么问题,此外,Doctrine 和 Symfony 创建了 SQL 查询。谁能指出我在这里做错了什么?这对我来说真是令人头疼。