Considering that you want to add extra fields on a relation, then it's not a relation anymore but clearly -"designly" speaking- an association object.
Hence, what you want in your "table document service" table is something like that
Document ------- Table document service -------- Service
Doing so means 2 things :
Many to one associations between Document ---- Table document service and Table document service -------- Service
A sort of "Composite key" in the Table document service entity based on these associations (your primarykey then becomes a composite of the relations between these objects.
Here are some examples : as you can see in the official doctrine 2 documentation you can do assotiations based on manytoone with composite keys as follow.
EDIT : here is some bunch of code, trying to follow your example.
use Doctrine\ORM\Mapping\Entity, Doctrine\ORM\Mapping\Id, Doctrine\ORM\Mapping\Column, Doctrine\ORM\Mapping\ManyToOne, Doctrine\ORM\Mapping\OneToMany;
/** @Entity */
class Document
{
/** @Id @Column(type="integer") @GeneratedValue */
protected $id;
/** @OneToMany(targetEntity="OrderItem", mappedBy="document") */
protected $tableDocumentService;
/** your attributes here, it isn't important here **/
public function __construct(Customer $customer)
{
$this->tableDocumentService = new ArrayCollection();
// some logic here if you need it
}
}
/** @Entity */
class Service
{
/** @Id @Column(type="integer") @GeneratedValue */
protected $id;
/** @Column(type="string) *§
protected $name;
}
/** @Entity */
class TableDocumentService
{
/** @Id @ManyToOne(targetEntity="Document") */
protected $document;
/** @Id @ManyToOne(targetEntity="Service") */
protected $service;
/** @Column(type="integer") */
protected $amount = 1;
}
I can add that, I guess, you can add too another OneToMany association in the Service class as the doc did for the Document entity, something like
/** @OneToMany(targetEntity="OrderItem", mappedBy="service") */
protected $tableDocumentService;