Doctrine2,在1个实体中使用2个表

时间:2013-06-27 07:20:01

标签: php doctrine-orm doctrine entities

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

我有以下表结构:

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
}
?>

任何帮助都非常适合。

1 个答案:

答案 0 :(得分:0)

我认为这就是你要找的东西

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

有关详细信息,请参阅Docmentation