Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doctrine 2 manytoone relationship with custom field name

I'm using Doctrine 2 to connect to and generate objects from a mysql database that is a shared backend to a filemaker application. As such, i cannot let Doctrine completely automate the table generation and need to customise the mapping from class property to db table fields. The following annotation, by default, maps to the table field 'pubofficeid_id'. I need it to map to 'pubofficeid'. Is this possible? I can change anything in the annotation or the class property name.

/**
 * @ManyToOne (targetEntity="Hs_Profile_Staff", inversedBy="staffPubRelation", cascade={"persist"})
 */
public $pubofficeid;
like image 301
waigani Avatar asked Mar 20 '11 21:03

waigani


1 Answers

The One-To-Many, Bidirectional example in the documentation spells it out pretty clearly.

class Feature
{
    // ...
    /**
     * @ManyToOne(targetEntity="Product", inversedBy="features")
     * @JoinColumn(name="product_id", referencedColumnName="id")
     */
    private $product;
    // ...
}
like image 99
Phil Avatar answered Sep 19 '22 09:09

Phil