1

私はここでは初めてで、symfony2はまったく初めてです。

エンティティ'Process'から継承するエンティティ'MailProcess'を作成しようとしています。これが私のエンティティ定義です:

// 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クラステーブル継承を確認できます。2つのテーブル「process」と「process_mailprocess」と識別子列「process_type」。

私は「phpapp/console doctrine:schema:update --force」を使用して、スキーマをMySQLデータベースに更新します。これは正常に機能します。

しかし、データフィクスチャがあります。ここではそれらを1つに減らしましたが、正常に機能しているエンティティ「プロセス」をテストする追加のフィクスチャがあることを確認してください。

// 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 doctrine: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クエリを作成します。誰かが私がここで間違っていることを指摘できますか?これは私にとって本当のヘッドスクラッチャーです。

4

1 に答える 1

0

fromはMySqlの予約語であるため、構文エラーが発生すると思います。注釈に列名を設定し、適切に引用することができます。

/**
 *
 * @ORM\Column(type="string", name="`from`") 
 */
protected $from;
于 2013-03-08T20:57:37.287 に答える