【问题标题】:Symfony 3 and Doctrine Link TableSymfony 3 和 Doctrine 链接表
【发布时间】:2017-11-30 10:57:04
【问题描述】:

我的目标是为 Symfony3 和 Doctrine 中的翻译创建术语表。

  • 一个表 (TERMS) 应包含主键 ID 和术语。
  • 第二个表 (TermLink) 应该包含 Term 与其翻译之间的链接,它也是一个 Term,例如:TermId | 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;
}

任何帮助将不胜感激,在此先感谢您。

【问题讨论】:

    标签: php mysql symfony doctrine-orm


    【解决方案1】:

    首先看这里:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html OR https://symfony.com/doc/current/doctrine/associations.html

    其次,这应该是一个好的开始:

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

    关于上述内容的公共卫生警告:

    直接从我的头顶出发,无法解决问题,可能会被关闭。但是你想要什么的原则应该可以从那里得到。

    【讨论】:

    • 感谢您的回答。 termId 和 translationId 中的 TargetEntity 都是术语实体(表)。条款表还必须包含有关 TranslLink 的 OneToMany 关系?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 2011-01-15
    相关资源
    最近更新 更多