doctrine:设置与id而不是对象实例的关联(doctrine: setting association with id instead of object instance)
是否可以设置两个对象之间的关联,例如article和comment :
comment.setArticle(10) // 10 is the id of article自动生成setArtcicle方法作为参数对象文章当然,但也许有一些技巧来做到这一点?
从性能角度来看,对我来说非常重要 - 我想避免在我想要设置一个关联时总是使用SQL调用。 在我的情况下,会有很多这样的不必要的查询。
is it possible to set associations between two objects, for example article and comment like this:
comment.setArticle(10) // 10 is the id of articleautogenerated setArtcicle methods takes as argument object Article of course but maybe there are some tricks to do this?
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));You can use:
$comment->setArticle($em->getReference('Article', 10));更多推荐
发布评论