doctrine: setting association with id instead of o

2019-03-07 23:01发布

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.

1条回答
Bombasti
2楼-- · 2019-03-07 23:46

You can use:

$comment->setArticle($em->getReference('Article', 10));
查看更多
登录 后发表回答