Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doctrine: setting association with id instead of object instance

Tags:

doctrine-orm

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.

like image 335
mkk Avatar asked Feb 16 '12 09:02

mkk


1 Answers

You can use:

$comment->setArticle($em->getReference('Article', 10));
like image 155
meze Avatar answered Nov 05 '22 23:11

meze