嗨我正在尝试创建这样的映射
class Users
{
/**
* @var integer
*
* @ORM\Column(name="id_users", type="smallint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100, nullable=true)
*/
private $name;
/**
*
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="UsersEmailAddresses", mappedBy="users")
* @ORM\JoinColumn(name="id_users", referencedColumnName="users_id")
*/
private $email;
和
class UsersEmailAddresses
{
/**
* @var integer
*
* @ORM\Column(name="id_users_email_adresses", type="smallint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=100, nullable=true)
*/
private $email;
/**
* @var \Users
* @ORM\Column(name="users_id")
* @ORM\OneToMany(targetEntity="Users")
*/
private $users;
当我尝试向一位用户显示多封电子邮件时,例如
<td>{{ entity.name }}</td>
<td><ul>
{% for e in entity.email %}
<li>{{ e.email }}</li>
{% endfor %}
</ul></td>
我得到了像这样的错误An exception has been thrown during the rendering of a template ("Notice: Undefined index: users in /var/www/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1575") in /var/www/symfony/src/Test/UserBundle/Resources/views/Users/index.html.twig at line 22
22行是for
循环