Hi Mohsen, You either map the fields as @Column or as association: both is not supported.
Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 8 September 2015 at 14:06, Mohsen Saberi <[email protected]> wrote: > Hello, > I built 3 entities that i want ID of one of tables be foreign key for 2 > others tables > Doctrine didnt make foreign key between these classes, whats my mistake? > > > > class class1 > { > /** > * @var integer > * > * @ORM\Column(name="id", type="integer") > * @ORM\Id > * @ORM\GeneratedValue(strategy="AUTO") > */ > private $id; > > /** > * @var integer > * > * @ORM\Column(name="fkey", type="integer") > * @ORM\ManyToOne(targetEntity="class2") > * @ORM\JoinColumn(name="f_key", referencedColumnName="id") > */ > private $fkey; > } > > > class class2 > { > /** > * @var integer > * > * @ORM\Column(name="id", type="integer") > * @ORM\Id > * @ORM\GeneratedValue(strategy="AUTO") > * @ORM\OneToMany(targetEntity="class1", mappedBy="f_key") > * @ORM\OneToMany(targetEntity="class3", mappedBy="id_id") > */ > private $id; > > /** > * @var integer > * > * @ORM\Column(name="fkey", type="integer") > */ > private $fkey; > } > > > class class3 > { > /** > * @var integer > * > * @ORM\Column(name="id", type="integer") > * @ORM\Id > * @ORM\GeneratedValue(strategy="NONE") > * @ORM\ManyToOne(targetEntity="class2") > * @ORM\JoinColumn(name="id_id", referencedColumnName="id") > */ > private $id; > > /** > * @var integer > * > * @ORM\Column(name="fkey", type="integer") > */ > private $fkey; > } > > Result of php console doctrine:schema:create --dump-sql : > > CREATE TABLE class1 (id INT AUTO_INCREMENT NOT NULL, fkey INT NOT NULL, > PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci > ENGINE = InnoDB; > CREATE TABLE class2 (id INT AUTO_INCREMENT NOT NULL, fkey INT NOT NULL, > PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci > ENGINE = InnoDB; > CREATE TABLE class3 (id INT NOT NULL, fkey INT NOT NULL, PRIMARY KEY(id)) > DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB; > > Can anyone help on this issue? > Best Regards > > -- > You received this message because you are subscribed to the Google Groups > "doctrine-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/doctrine-user. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
