我正在使用 Doctrine 和这三个(相关)实体运行 Symfony 2.3:出版物, Author and 作者发表.
Both, Author and 出版物具有多对一关系作者发表(所以它基本上是一个多对多关系Author and 出版物但我需要作者发表订购出版物作者的实体)
我想要一个表单,用户可以在其中创建新出版物并根据需要为该出版物选择尽可能多的作者。
我研究了这篇文章:如何嵌入表单集合 http://symfony.com/doc/current/cookbook/form/form_collections.html但我不明白如何将其应用于我的问题,因为作者发表介于两者之间的实体。
相关代码:
出版物
<?php
namespace ind\PubBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="ind\PubBundle\Repository\PublicationRepository")
* @ORM\Table("publications")
*/
class Publication {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $pid;
/**
* @ORM\OneToMany(targetEntity="AuthorPublication", mappedBy="publication")
* @ORM\OrderBy({"order_id" = "ASC"})
*/
protected $publicationAuthors;
//some more attributes + getters/seters
?>
Author
<?php
namespace ind\PubBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table("aid_author")
*/
class Author {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $aid;
/**
* @ORM\Column(type="string", length=255)
*/
protected $author_surname;
/**
* @ORM\Column(type="string", length=255)
*/
protected $author_forename;
/**
* @ORM\OneToMany(targetEntity="AuthorPublication", mappedBy="author")
*/
protected $authorPublication;
?>
作者发表
<?php
namespace ind\PubBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table("aid_pid")
*/
class AuthorPublication {
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
protected $aid;
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
protected $pid;
/**
* @ORM\Column(type="integer")
*/
protected $order_id;
/**
* @ORM\ManyToOne(targetEntity="Publication", inversedBy="publicationAuthors")
* @ORM\JoinColumn(name="pid", referencedColumnName="pid")
*/
protected $publication;
/**
* @ORM\ManyToOne(targetEntity="Author", inversedBy="authorPublication")
* @ORM\JoinColumn(name="aid", referencedColumnName="aid")
*/
protected $author;
?>