2017-11-30 15 views
1

私の目標は、Symfony3とDoctrineで翻訳用のTermテーブルを作成することです。Symfony 3とDoctrine Link Table

  • テーブル(TERMS)には、主キーIDと用語が含まれている必要があります。
  • 2番目の表(TermLink)には、Termとその翻訳のリンクが含まれている必要があります。 TranslationId - これらは同じプライマリキーの外部キーです - 用語IDフィールド。 これを達成するには、Doctrine Documentationという複数のアプローチがありますが、どれも自分のニーズに合っていません。

ここで私が実現したいと思い、私の実際のエンティティは以下のとおりです。

用語表:

/** 
* Translation Term 
* 
* @ORM\Table(name="translation_term") 
* @ORM\Entity‚ 
*/ 
class TranslTerm 
{ 
    /** 
    * @var int 
    * 
    * @ORM\Column(name="term_id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $termId; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="term", type="string", length=128) 
    */ 
    private $term; 
} 

リンク表:

/** 
* Translation Link - One To Many/JoinTable - 
* 
* @ORM\Table(name="translation_link") 
* @ORM\Entity‚ 
*/ 
class TranslLink 
{ 
    private $id; 
    private $termId; 
    private $translationId; 
} 
は、任意の助けをいただければ幸い

、ありがとうございましたあらかじめ。

答えて

0

まずここを見て:

class TranslLink 
{ 
    private $id; 
    /** 
    * @ORM\ManyToOne(targetEntity="Terms", mappedBy="trans_link") 
    */ 
    private $termId; 
    /** 
    * @ORM\ManyToOne(targetEntity="Translations", mappedBy="trans_link") 
    */ 
    private $translationId; 
} 

より約公衆衛生警告:

まっすぐ私の頭の上を離れるhttp://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html OR https://symfony.com/doc/current/doctrine/associations.html

は、第二に、ここで良いスタートべきものです箱を動かすことができず、オフになる可能性があります。しかし、あなたが望むものの原則は、そこから得られるはずです。

+0

ありがとうございます。 termIdとtranslationIdの両方のTargetEntityは、用語エンティティ(テーブル)です。また、Termsテーブルには、TranslLinkに関するOneToMany関係が含まれている必要がありますか? – Francis

関連する問題