Doctrine, Issue with Custom Join Table

Continuing the discussion from Doctine, Custom Join Table:

Done what exactly? How have you solved this particular problem? I am having the same problem myself :-/

Thanks.

Going to need a bit more information. I’m assuming you are following the manual: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#many-to-many-unidirectional ?

Would it be possible to check your entities into github and provide a link?

If not then please post the source code for your Model and Feature entities.

The concept of creating custom join tables is simple, really. There is no special syntax or relationship declaration needed.

You don’t want Doctrine to be trying to maintain the ManyToMany relationship for you, but instead create it manually by defining a Join Entity and manually creating the required ManyToOne relationships.

Consider this simplified example:

/** @Entity **/
class Shop {
    // ...
}

/** @Entity **/
class Product {
    // ...
}

/** @Entity **/
class ProductStock {   
    /** @Id @ManyToOne(targetEntity="Shop") **/
    private $shop;
    
    /** @Id @ManyToOne(targetEntity="Product") **/
    private $product
    
    /** @Column(type="integer") **/
    private $amount;
}

Of course this is very generic. If you want more specific help, post more details about your specific situation. The entity definitions would be especially useful.

Not necessarily. If your join table has no additional attributes then ManyToMany will simplify your code.

But I kind of gather that this is an older thread.

@ahundiak, Yes, that’s true, but the question was specifically about custom join tables, as was my answer. I’m certainly not recommending creating custom join tables for ManyToMany relationships that don’t require any custom attributes. Doctrine handles that just fine.

My bad. Gotta learn to read the question more carefully.