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

编程入门 行业动态 更新时间:2024-10-24 16:25:46
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 article

autogenerated 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));

更多推荐

本文发布于:2023-07-16 12:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是   实例   对象   id   doctrine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!