doctrine:设置与id而不是对象实例的关联 [英] doctrine: setting association with id instead of object instance

查看:95
本文介绍了doctrine:设置与id而不是对象实例的关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以设置两个对象之间的关联,例如文章注释,如下所示:

is it possible to set associations between two objects, for example article and comment like this:

comment.setArticle(10) // 10 is the id of article

自动生成setArtcicle方法作为参数对象文章当然,但也许有一些技巧这样做?

autogenerated setArtcicle methods takes as argument object Article of course but maybe there are some tricks to do this?

它从性能角度来看,对我来说非常重要 - 我想避免在要设置关联时总是使用SQL调用。在我的情况下会有很多这样的不必要的查询。

It is very important to me from performance point of view - i would like to avoid making SQL calls always when I want to set an association. In my case there will be plenty of such unnecessary queries.

推荐答案

你可以使用:

$comment->setArticle($em->getReference('Article', 10));

这篇关于doctrine:设置与id而不是对象实例的关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆