【问题标题】:Doctrine2, using 2 tables in 1 entityDoctrine2,在 1 个实体中使用 2 个表
【发布时间】:2013-06-27 07:20:00
【问题描述】:

我正在寻找一种在一个 Doctrine 2 实体类中使用多个表(一对一)的方法。这可以使用简单的注释来实现吗?添加更多类不是我想做的事情。

我的表结构如下:

Attribute:
    id
    type_id
    value
AttributeType:
    id
    name
    unit

我想做的是创建一个实体,它基本上可以为来自同一类的 2 个表调用 getter 和 setter,而不必创建单独的实体类,例如:

<?php
class Attribute {
    public function getName(){ return $this->name; } // From AttributeType
    public function getValue(){ return $this->value; } // From Attribute
}
?>

非常感谢任何帮助。

【问题讨论】:

    标签: php doctrine-orm doctrine entities


    【解决方案1】:

    我想这就是你要找的东西

    /**
     * @OneToOne(targetEntity="AttributeType")
     * @JoinColumn(name="type_id", referencedColumnName="id")
     */
    

    更多详情请参考Docmentation

    【讨论】:

    • 不,抱歉。这需要我创建一个 AttributeType 实体类。我想将 2 个表合并为一个实体,而不必编写 2 个单独的类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    相关资源
    最近更新 更多