小编ikh*_*lev的帖子

Doctrine2将不可变字段移动到单独的类中

我需要将一些不可变字段移动到单独的类中,但我真的不想使用"join",因为我每次都需要所有数据.

有没有办法让一些实体属性作为映射到同一个表的类?

就像是:

/**
 * @ORM\Entity
 */
class User {
    /**
     * @var int
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
    ...

    /**
     * @var Address
     * @ORM\... ??
     */
    protected $address
}

/**
 * @ORM\ValueObject ??
 */
class Address {
    /**
     * @var string
     * @ORM\Column(type="string", name="address_zipcode", length=12)
     */
    protected $zipcode;

    /**
     * @var string
     * @ORM\Column(type="string", name="address_country_iso", length=3)
     */
    protected $countryIso;
    ...
}
Run Code Online (Sandbox Code Playgroud)

表结构将是:

CREATE TABLE User (
    `id` INT(11) NOT NULL auto_increment,
    `address_zipcode` VARCHAR(12) NOT …
Run Code Online (Sandbox Code Playgroud)

php mysql doctrine-orm

12
推荐指数
1
解决办法
442
查看次数

标签 统计

doctrine-orm ×1

mysql ×1

php ×1