gpt4 book ai didi

symfony - 延迟加载与原则一一对应

转载 作者:行者123 更新时间:2023-12-03 14:15:13 31 4
gpt4 key购买 nike

我很难找到正确的结果。

我有一对一的映射。有两个表:

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

/**
* @ORM\OneToOne(targetEntity="UsersSettings", mappedBy="user",cascade={"persist"})
*/
private $userSetting;

//getters and setters
}

/**
* @ORM\Table(name="notifications_settings")
* @ORM\Entity
*/
class UsersSettings {

/**
* @var Users
*
* @ORM\OneToOne(targetEntity="Users", inversedBy="userSetting")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
}


每当我获取实体一如下:

$q = $this
->createQueryBuilder('u')
->select('u, r')
->leftJoin('u.roles', 'r')
->where('u.username = :username OR u.email = :email')
->setParameter('username', $username)
->setParameter('email', $username)
->getQuery();


教义立即对我不想要的usersSettings实体执行联接:


选择t0.id AS id1,t0.username AS用户名2,t0.email AS email3,t0.password AS password4,t29.id AS id30,t29.is_notify_by_email AS
is_notify_by_email31,t29.user_id AS user_id32来自用户t0左联接
users_settings t29 ON t29.user_id = t0.id W0位置t0.id =?


其他类型的映射(例如 OneToManyManyToOne)执行延迟加载,但是在一对一映射的情况下,我无法配置为延迟加载。我该如何懒惰加载此关系?我正在使用教义2.3和Symfony 2.1

最佳答案

使用提示HINT_FORCE_PARTIAL_LOAD避免延迟加载。

...
$qb->getQuery()->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);

关于symfony - 延迟加载与原则一一对应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14431869/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com