doctrine2 - How can I implement a OneToMany association with a separate link table? -


i'm implementing new application on top of existing database. existing database being used mobile application , because mobile app being developed different team not allowed change structure of existing tables.

the existing database has user table , own application's users created own table , doctrine entity called portaluser (table portal_user).

the portaluser entity going have onetomany association called $children refers existing user entity. in other words each portaluser has 0 or more child user entities.

the natural way implement have (simplified):

user (the existing entity):

class user {     /**      * @var integer      *      * @orm\column(name="id", type="integer", nullable=false)      * @orm\id      * @orm\generatedvalue(strategy="identity")      */     private $id;      /**      * @var portaluser      *      * @orm\manytoone(targetentity="portaluser", inversedby="children")      * @orm\joincolumn(name="parent_id", referencedcolumnname="id")      */     private $parent; } 

portaluser entity:

class portaluser {     /**      * @var  int      * @orm\id      * @orm\column(type="integer")      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * @var array      * @orm\onetomany(targetentity="user", mappedby="parent")      */     protected $children; } 

this create new column "parent_id" in existing user table isn't allowed. possible separate link table parent_id , child_id columns, equivalent regular manytomany link table? , if annotations result in such structure?

okay embarrassing. turns out it's in doctrine documentation:

a unidirectional one-to-many association can mapped through join table. doctrine’s point of view, mapped unidirectional many-to-many whereby unique constraint on 1 of join columns enforces one-to-many cardinality.

doctrine manual


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -