A new entity was found through the relationship doctrine error

Doctrine error: New Entity was found through relationship

This is typical problem of doctrine with joined relations.

How to use MySQL keyword as column in doctrine

And, to be specific, this would happen when trying to save an entity with relationship and the one being joined is fetched from memcached/redis or from other entity manager or you just populated it and not getting through Entity Manager

Solution to the doctrine error

Use the merge on EntityManager before you persist the object

Say you have an entity for pen and entity for color as well.. You want to save a new pen but you assigned a color from memcached object


$color = $this->memcacheGiveMeColor('blue');
$color = $em->merge($color)
$pen->setColor($color);
$em->persist($pen);
$em->flush();

Make sure you are using the object that is returned from merge!

If you are not reading from the memcached or other factory, and you are reading directly from Entity Manager then you wont have this error.

Start using mongoDB with nodeJS even though you haven’t been using it before

What is http raw data? what is php://input and where to use which?