我很难为此找到正确的结果。
我有一对一的映射。有两个表:
/**
* @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();
Doctrine 立即加入我不想要的 usersSettings 实体:
SELECT t0.id AS id1, t0.username AS username2, 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 FROM users t0 LEFT JOIN users_settings t29 ON t29.user_id = t0.id 在哪里 t0.id = ?
其他类型的映射喜欢OneToMany
并ManyToOne
执行延迟加载,但在一对一映射的情况下,我无法配置为延迟加载。我怎样才能延迟加载这种关系?我正在使用学说 2.3 和 Symfony 2.1