Last Updated: February 25, 2016
·
2.676K
· devalien

Doctrine using an id instead of passing the object

For example you get a list of IDS and you don't need to get an object querying the database, you can do just a simple trick.
$em->getReference('ENTITY',$id);

Example:
$post->setCategory('Category', $id);

or in symfony:
$post->setCategory('CompanyNameBundle:Category', $id);

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside