Reputation: 11
I try to make a join table from 2 entities with a manytomany relationship like this:
class Entity1
{
/**
* @ORM\ManyToMany(targetEntity="Orders")
* @JoinTable(name="users_orders",
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="order_id", referencedColumnName="id", unique=true)
*/
private $orders;
}
but each time I try to generate the getters and setters I have the same error:
The annotation @JoinTable... was never imported. Did you forget to add a use statement for this annotation?
So how can I add the use statement? Thank you for your help
Upvotes: 1
Views: 806
Reputation: 2140
Add ORM in front of JoinTable
and JoinColumn
/**
* @ORM\ManyToMany(targetEntity="Orders")
* @ORM\JoinTable(name="users_orders",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="order_id", referencedColumnName="id", unique=true)
*/
And add the 'use'-statement at the top of your class:
use Doctrine\ORM\Mapping as ORM;
Upvotes: 5
Reputation: 8276
You need to put @ORM\
in front of all of your Doctrine annotations:
/**
* @ORM\ManyToMany(targetEntity="Orders")
* @ORM\JoinTable(name="users_orders",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="order_id", referencedColumnName="id", unique=true)
*/
private $orders;
Upvotes: 3