ManyToOne教义关系未加载

时间:2018-08-23 17:45:55

标签: php doctrine-orm orm doctrine zend-expressive

我有以下两个实体:

/**
 * @ORM\Entity
 * @ORM\Table(name="Users")
 */
class user
{
...

/**
* @OneToMany(targetEntity="tournamentEntry", mappedBy="user", fetch="LAZY")
*/
private $tournamentEntries;

public function __construct() {
    $this->tournamentEntries = new ArrayCollection();
}

并且:

/**
 * @ORM\Entity
 * @ORM\Table(name="TournamentEntry")
 */
class tournamentEntry
{
...

/**
* @ManyToOne(targetEntity="User", inversedBy="tournamentEntries")
* @JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
}

获取用户时的正常查询(即使调用 getTournamentEntries()时)是

SELECT t0.id AS id_1, ... FROM Users t0 WHERE t0.username = 'user2323' LIMIT 1

如果我有机会使用EAGER的提取方法,则会执行另一个查询:

SELECT t0.id AS id_1, ... t0.user_id AS user_id_4 FROM TournamentEntry t0 WHERE t0.user_id = 1

即使此查询具有直接在数据库上执行时返回的记录,它也不会更改最终对象。

{
    "id": 1,
    ...
    "username": "user2323",
    ...
    "tournament_entries": {},
    "_links": {
        "self": {
            "href": "http://localhost:8080/me"
        }
    }
}

0 个答案:

没有答案