php - Doctrine with association and inheritance -


i have problem doctrine, inheritance, , mapping. it's web game, based on city management. won't copy code not because it's secret, because have fit in here.

the general design goes follow :

each town have multiple structure relatively similar, decided mappedsuperclass go follow

/** * @orm\mappedsuperclass */  class structuressuperclass{  /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue */ private $id;  /** * @orm\manytoone(targetentity="buildingtype") * @orm\joincolumn(ondelete="cascade") */ private $type;  /** * @orm\manytoone(targetentity="town", cascade={"persist"}) * @orm\joincolumn(ondelete="cascade") */ private $town; 

in structures there routes, buildings , in buildings there special on towncenter have it's own entity go follow :

routes:

use spagi\gamebundle\entity\structuressuperclass ssc;  /**  * @orm\entity  * @orm\table(name="route")  */ class route extends ssc{  /** * @orm\onetomany(targetentity="routeorders", mappedby="route",  cascade={"all"}, orphanremoval=true) */ protected $orders;  /** * @orm\manytoone(targetentity="building", cascade={"persist", "remove"}) * @orm\joincolumn(ondelete="cascade") */ protected $origin;  /** * @orm\manytoone(targetentity="building", cascade={"persist", "remove"}) * @orm\joincolumn(ondelete="cascade") */ protected $destination; 

buildings:

use spagi\gamebundle\entity\structuressuperclass ssc;  /** * @orm\entity * @orm\table(name="building") * @orm\inheritancetype("single_table") * @orm\discriminatorcolumn(name="discr", type="string") * @orm\discriminatormap({"tc" = "towncenter", "building" = "building"}) */  class building extends ssc{  /**  * @orm\onetoone(targetentity="inventory", cascade={"persist", "remove"})  * @orm\joincolumn(ondelete="cascade")  */ private $inventory;  /**  * @orm\column(type="integer")  */ private $radius;  /**  * @orm\column(type="integer")  */ private $theta; 

and towncenter:

use spagi\gamebundle\entity\building buildings;  /** * @orm\entity */  class towncenter extends buildings{ public function __construct(){     $this->setradius(0);     $this->settheta(0);     parent::__construct(); } 

in town entity need access each of these separatly created 3 onetomany

/** * @orm\entity * @orm\table(name="town") */  class town{  /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue */ protected $id;  /** snip **/  /**  * @orm\onetomany(targetentity="building", mappedby="town",  cascade={"all"}, orphanremoval=true)  */ protected $buildings;  /**  * @orm\onetomany(targetentity="towncenter", mappedby="town",  cascade={"all"}, orphanremoval=true)  */ protected $towncenter;  /**  * @orm\onetomany(targetentity="route", mappedby="town",  cascade={"all"}, orphanremoval=true)  */ protected $routes; 

the problem receive doctrine warning entities invalid follow

the field spagi\gamebundle\entity\town#buildings on inverse side of bi-directional relationship, specified mappedby association on target-entity spagi\gamebundle\entity\building#town not contain required 'inversedby=buildings' attribute. field spagi\gamebundle\entity\town#towncenter on inverse side of bi-directional relationship, specified mappedby association on target-entity spagi\gamebundle\entity\towncenter#town not contain required 'inversedby=towncenter' attribute. field spagi\gamebundle\entity\town#routes on inverse side of bi-directional relationship, specified mappedby association on target-entity spagi\gamebundle\entity\route#town not contain required 'inversedby=routes' attribute. 

from understanding, lead performance degradation on time , growth of db. relation building#town, towncenter#town , route#town inherited same file. can't write inversedby={'buildings','towncenter','routes'} ( haven't tried doubts ).

however i'd know if there solution issue other defining $town in each entity , missing point inheritance.

you cannot mapping in superclass. have map town in every subclass.

so route have town mapped inversedby="route", , building have town mapped inversedby="building" etc.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -