dongshen2903 2015-08-08 15:29
浏览 41

Symfony2中用户实体的自动数据库查询

In Symfony2, I have these columns in a user entity:

 *
 * @ORM\OneToOne(targetEntity="User", inversedBy="lovername")
 * @ORM\JoinColumn(name="lover", referencedColumnName="id", onDelete = "SET NULL")
 */
private $lover;


/**
 * @ORM\OneToOne(targetEntity="User", mappedBy="lover", cascade={"persist"}, fetch="EXTRA_LAZY")
 **/
private $lovername;

The project is a dating website, where a user can send messages only to one user, which he/she chose. The column lover contains the id of user he/she chose to talk to.

It works properly, but it generates an additional SQL query. First Symfony downloads the row about the logged user and then every information about user which 'love' him, even if that information is useless. I need it only when user sends messages.

It is some way to write it/build database better? How do I control auto-generating queries in Symfony2?

  • 写回答

1条回答 默认 最新

  • dongwu9170 2015-08-08 21:45
    关注

    I've also faced a similar problem. It seems like LazyLoad doesn't work properly for OneToOne relationships in doctrine. See this question

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?