i have simple company table relations:
id name parentid 1 company1 0 2 company2 1 3 company3 1 4 company4 3
how can write doctrine annotation relate entries in table?
seems entities company, each company have name , related company manytoone relation.
your company entity should looks :
/** * company * * @orm\table() * @orm\entity */ class company { /** * @var integer * @orm\column(name="id", type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ protected $id; /** * @var string * @orm\column(name="name", type="string", length=100) */ protected $name; /** * @orm\manytoone(targetentity="company") * @orm\joincolumn(name="parentid", referencedcolumnname="id") */ protected $parent; }
for base class, should consider using php app/console doctrine:generate:entity
work you. you'll have add parent relation manually.
you should have @ symfony's book on topic : http://symfony.com/doc/current/book/doctrine.html.
all association mapping configuration explain in doctrine's docs : http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html
Comments
Post a Comment